mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-10-02 19:03:43 +00:00
feat: web dashboard and playground work
The NexusDashboard-parity dashboard (dDashboardServer) and everything built on it on the experimental branch: accounts, characters, properties and moderation tools, permissions shared with in-game slash commands, economy reports, World 3D and property 3D views with client scenery, scheduled events (features, vanity changes, live events, announcements, restarts), vanity files and events, the CDClient browser, the message inspector with saved captures, chat filter tools, community challenges, live ops, the AI moderator helper, and the server-side changes they need. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
70
tests/dWebTests/RequireAuthMiddlewareTests.cpp
Normal file
70
tests/dWebTests/RequireAuthMiddlewareTests.cpp
Normal file
@@ -0,0 +1,70 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include "RequireAuthMiddleware.h"
|
||||
#include "HTTPContext.h"
|
||||
#include "Web.h"
|
||||
|
||||
class RequireAuthMiddlewareTest : public ::testing::Test {
|
||||
protected:
|
||||
HTTPContext context;
|
||||
HTTPReply reply;
|
||||
|
||||
void Authenticate(uint8_t gmLevel, const std::string& source) {
|
||||
context.isAuthenticated = true;
|
||||
context.authenticatedUser = "tester";
|
||||
context.gmLevel = gmLevel;
|
||||
context.userData["auth_source"] = source;
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(RequireAuthMiddlewareTest, UnauthenticatedApiRequestGets401) {
|
||||
context.method = "GET";
|
||||
context.path = "/api/status";
|
||||
EXPECT_FALSE(RequireAuthMiddleware(0).Process(context, reply));
|
||||
EXPECT_EQ(reply.status, eHTTPStatusCode::UNAUTHORIZED);
|
||||
}
|
||||
|
||||
TEST_F(RequireAuthMiddlewareTest, UnauthenticatedPageRedirectsToLogin) {
|
||||
context.method = "GET";
|
||||
context.path = "/accounts";
|
||||
EXPECT_FALSE(RequireAuthMiddleware(1).Process(context, reply));
|
||||
EXPECT_EQ(reply.status, eHTTPStatusCode::FOUND);
|
||||
EXPECT_EQ(reply.location, "/login");
|
||||
}
|
||||
|
||||
TEST_F(RequireAuthMiddlewareTest, InsufficientLevelIsForbidden) {
|
||||
context.method = "GET";
|
||||
context.path = "/api/tables/audit_log";
|
||||
Authenticate(4, "header");
|
||||
EXPECT_FALSE(RequireAuthMiddleware(8).Process(context, reply));
|
||||
EXPECT_EQ(reply.status, eHTTPStatusCode::FORBIDDEN);
|
||||
}
|
||||
|
||||
TEST_F(RequireAuthMiddlewareTest, CookiePostWithoutCsrfHeaderIsRejected) {
|
||||
context.method = "POST";
|
||||
context.path = "/api/accounts/2/ban";
|
||||
Authenticate(9, "cookie");
|
||||
EXPECT_FALSE(RequireAuthMiddleware(4).Process(context, reply));
|
||||
EXPECT_EQ(reply.status, eHTTPStatusCode::FORBIDDEN);
|
||||
}
|
||||
|
||||
TEST_F(RequireAuthMiddlewareTest, CookiePostWithCsrfHeaderIsAllowed) {
|
||||
context.method = "POST";
|
||||
context.path = "/api/accounts/2/ban";
|
||||
context.SetHeader("X-Requested-With", "dashboard");
|
||||
Authenticate(9, "cookie");
|
||||
EXPECT_TRUE(RequireAuthMiddleware(4).Process(context, reply));
|
||||
}
|
||||
|
||||
TEST_F(RequireAuthMiddlewareTest, BearerPostDoesNotNeedCsrfHeader) {
|
||||
context.method = "POST";
|
||||
context.path = "/api/accounts/2/ban";
|
||||
Authenticate(9, "header");
|
||||
EXPECT_TRUE(RequireAuthMiddleware(4).Process(context, reply));
|
||||
}
|
||||
|
||||
TEST_F(RequireAuthMiddlewareTest, CookieGetDoesNotNeedCsrfHeader) {
|
||||
context.method = "GET";
|
||||
context.path = "/api/status";
|
||||
Authenticate(0, "cookie");
|
||||
EXPECT_TRUE(RequireAuthMiddleware(0).Process(context, reply));
|
||||
}
|
||||
Reference in New Issue
Block a user