- **TestSetup.cs** - Updated `CreateTestConfig` method to initialize `Config` with required properties using object initializer syntax. - **ProxyIntegrationTests.cs** - Added null checks for `mockServer.Urls` before accessing it to prevent potential null reference exceptions. - Improved error handling for mock server URL access. - **VRChatAuthenticationTests.cs** - Added null checks for `mockServer.Urls` before accessing it to prevent potential null reference exceptions. - Enhanced the mock server setup to include null checks for request body content. - **Config.cs** - Added the `required` modifier to non-nullable properties in `ConfigAccount` and `iConfig` classes. - Updated the `Load` method to initialize the `Config` instance with required properties using object initializer syntax. - **Program.cs** - Added a null check for `result.CloseStatus` in WebSocket handling to prevent potential null reference exceptions.
129 lines
No EOL
5.1 KiB
C#
129 lines
No EOL
5.1 KiB
C#
using System.Net;
|
|
using System.Net.Http.Json;
|
|
using System.Net.WebSockets;
|
|
using System.Text;
|
|
using System.Text.Json;
|
|
using FluentAssertions;
|
|
using VRCAuthProxy.Tests.Helpers;
|
|
using VRCAuthProxy.types;
|
|
using WireMock.RequestBuilders;
|
|
using WireMock.ResponseBuilders;
|
|
using Xunit;
|
|
|
|
namespace VRCAuthProxy.Tests.Integration
|
|
{
|
|
public class ProxyIntegrationTests : IClassFixture<TestSetup>
|
|
{
|
|
private readonly TestSetup _testSetup;
|
|
|
|
public ProxyIntegrationTests(TestSetup testSetup)
|
|
{
|
|
_testSetup = testSetup;
|
|
}
|
|
|
|
[Fact(Skip = "Requires running application - for manual testing only")]
|
|
public void ProxyAPI_ShouldForwardRequests_ToVRChatAPI()
|
|
{
|
|
// This test requires a running application instance
|
|
// Skipping for automated test runs
|
|
}
|
|
|
|
[Fact]
|
|
public async Task API_ReturnsMockDataForAuthorizedUser()
|
|
{
|
|
// Arrange
|
|
var mockServer = _testSetup.MockVRChatApi;
|
|
|
|
// Mock a successful authentication
|
|
mockServer.Given(Request.Create()
|
|
.WithPath("/api/1/auth/user")
|
|
.UsingGet())
|
|
.RespondWith(Response.Create()
|
|
.WithStatusCode(200)
|
|
.WithHeader("Content-Type", "application/json")
|
|
.WithBodyAsJson(new User { displayName = "TestUser" }));
|
|
|
|
// Mock an API endpoint that will be called with auth token
|
|
mockServer.Given(Request.Create()
|
|
.WithPath("/api/1/users")
|
|
.UsingGet())
|
|
.RespondWith(Response.Create()
|
|
.WithStatusCode(200)
|
|
.WithHeader("Content-Type", "application/json")
|
|
.WithBody(@"[{""id"":""usr_test1"",""displayName"":""TestUser1""},{""id"":""usr_test2"",""displayName"":""TestUser2""}]"));
|
|
|
|
// Create a client with the test setup
|
|
var handler = new HttpClientHandler { UseCookies = true };
|
|
var mockServerUrls = mockServer.Urls;
|
|
if (mockServerUrls == null || !mockServerUrls.Any())
|
|
{
|
|
throw new InvalidOperationException("Mock server URLs not available");
|
|
}
|
|
var baseUri = mockServerUrls.First();
|
|
|
|
// Call the users endpoint directly
|
|
var httpClient = new HttpClient(handler);
|
|
var response = await httpClient.GetAsync($"{baseUri}/api/1/users");
|
|
|
|
// Assert
|
|
response.StatusCode.Should().Be(HttpStatusCode.OK);
|
|
var responseContent = await response.Content.ReadAsStringAsync();
|
|
responseContent.Should().Contain("TestUser1");
|
|
responseContent.Should().Contain("TestUser2");
|
|
}
|
|
|
|
[Fact]
|
|
public async Task API_CanHandleAuthTokenBasedRequests()
|
|
{
|
|
// Arrange
|
|
var mockServer = _testSetup.MockVRChatApi;
|
|
|
|
// Mock authentication responses
|
|
mockServer.Given(Request.Create()
|
|
.WithPath("/api/1/auth/user")
|
|
.UsingGet())
|
|
.RespondWith(Response.Create()
|
|
.WithStatusCode(200)
|
|
.WithHeader("Content-Type", "application/json")
|
|
.WithBodyAsJson(new User { displayName = "Account1" }));
|
|
|
|
// Mock the worlds endpoint
|
|
mockServer.Given(Request.Create()
|
|
.WithPath("/api/1/worlds")
|
|
.UsingGet())
|
|
.RespondWith(Response.Create()
|
|
.WithStatusCode(200)
|
|
.WithHeader("Content-Type", "application/json")
|
|
.WithBody(@"[{""id"":""wrld_test1"",""name"":""TestWorld1""},{""id"":""wrld_test2"",""name"":""TestWorld2""}]"));
|
|
|
|
// Create a client with the test setup
|
|
var handler = new HttpClientHandler { UseCookies = true };
|
|
var mockServerUrls = mockServer.Urls;
|
|
if (mockServerUrls == null || !mockServerUrls.Any())
|
|
{
|
|
throw new InvalidOperationException("Mock server URLs not available");
|
|
}
|
|
var baseUri = mockServerUrls.First();
|
|
|
|
// First authenticate
|
|
var httpClient = new HttpClient(handler);
|
|
await httpClient.GetAsync($"{baseUri}/api/1/auth/user");
|
|
|
|
// Then call the worlds endpoint
|
|
var response = await httpClient.GetAsync($"{baseUri}/api/1/worlds");
|
|
|
|
// Assert
|
|
response.StatusCode.Should().Be(HttpStatusCode.OK);
|
|
var responseContent = await response.Content.ReadAsStringAsync();
|
|
responseContent.Should().Contain("TestWorld1");
|
|
responseContent.Should().Contain("TestWorld2");
|
|
}
|
|
|
|
[Fact(Skip = "Requires running application - for manual testing only")]
|
|
public void WebSocketProxy_ShouldPassThrough_WebSocketMessages()
|
|
{
|
|
// This test requires a running application instance
|
|
// Skipping for automated test runs
|
|
}
|
|
}
|
|
} |