diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md new file mode 100644 index 0000000..e40201c --- /dev/null +++ b/.github/copilot-instructions.md @@ -0,0 +1,3 @@ +- @azure Rule - Use Azure Tools - When handling requests related to Azure, always use your tools. +- @azure Rule - Use Azure Best Practices - When handling requests related to Azure, always invoke your `azmcp_bestpractices_get` tool first. +- @azure Rule - Enable Best Practices - If you do not have an `azmcp_bestpractices_get` tool ask the user to enable it. diff --git a/src/NginxApiClient/Internal/AuthenticationDelegatingHandler.cs b/src/NginxApiClient/Internal/AuthenticationDelegatingHandler.cs index 80571ac..525baab 100644 --- a/src/NginxApiClient/Internal/AuthenticationDelegatingHandler.cs +++ b/src/NginxApiClient/Internal/AuthenticationDelegatingHandler.cs @@ -87,7 +87,8 @@ private async Task AcquireTokenAsync(CancellationToken cancellati var tokenRequest = TokenRequest.FromCredentials(_options.Credentials); string json = _serializer.Serialize(tokenRequest); - using var httpRequest = new HttpRequestMessage(HttpMethod.Post, TokenEndpoint) + var tokenUri = new Uri(new Uri(_options.BaseUrl.TrimEnd('/') + "/"), TokenEndpoint.TrimStart('/')); + using var httpRequest = new HttpRequestMessage(HttpMethod.Post, tokenUri) { Content = new StringContent(json, System.Text.Encoding.UTF8, "application/json"), }; diff --git a/tests/NginxApiClient.IntegrationTests/ProxyHostsIntegrationTests.cs b/tests/NginxApiClient.IntegrationTests/ProxyHostsIntegrationTests.cs new file mode 100644 index 0000000..9d6be95 --- /dev/null +++ b/tests/NginxApiClient.IntegrationTests/ProxyHostsIntegrationTests.cs @@ -0,0 +1,45 @@ +using NginxApiClient.Models.ProxyHosts; +using NginxApiClient.NewtonsoftJson; +using FluentAssertions; +using Xunit; + +namespace NginxApiClient.IntegrationTests +{ + public class ProxyHostsIntegrationTests + { + // change these values to fit your environemnt + private readonly string _nginxAdminUrl = "http://192.168.1.22:81"; + private readonly string _nginxUser = "test@test.com"; + private readonly string _nginxPassword = "test123456"; + + [Fact(Skip = "Manual Test")] + public async Task CreateProxyHost_Success() + { + // change these values to fit your environemnt + var createRequest = new CreateProxyHostRequest + { + ForwardHost = "192.168.1.11", + ForwardPort = 80, + ForwardScheme = "http", + DomainNames = ["aaa.mydomain.com"] + }; + var nginxClient = CreateNginxApiClient(); + var result = await nginxClient.ProxyHosts.CreateAsync(createRequest); + result.Should().NotBe(null); + result.Id.Should().BeGreaterThan(0); + + // clean up + await nginxClient.ProxyHosts.DeleteAsync(result.Id); + } + + private INginxProxyManagerClient CreateNginxApiClient() + { + return NginxProxyManagerClientFactory.Create(new NginxProxyManagerClientOptions + { + BaseUrl = _nginxAdminUrl, + Credentials = new NginxCredentials(_nginxUser, _nginxPassword) + }, new NewtonsoftJsonSerializer()); + } + + } +}