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 { 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 } } }