Skip to content

Commit

Permalink
Updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Aldaviva committed Jun 25, 2024
1 parent fb0ffc7 commit 75eb691
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 17 deletions.
15 changes: 8 additions & 7 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,17 @@ This is an alternative to filling out monthly CAPTCHAs for [No-IP](https://www.n
```

## Configuration
Open `appsettings.json` in a text editor.
Open `appsettings.json` in a text editor and fill in the following values. Keys marked with ✴ are the most important ones to configure.

|Key|Type|Examples|Description|
|-|-|-|-|
|`gandiApiKey`|`string`|`abcdefg`|Generate an API key under [Developer access](https://account.gandi.net/en/users/_/security) in your [Gandi Account](https://account.gandi.net/en). Personal Access Tokens are unfortunately not supported by [G6.GandiLiveDns](https://github.com/gaylord-roger/G6.GandiLiveDns).|
|`domain`|`string`|`example.com`<br>`example.co.uk`|The second-level domain name that you registered, including the TLD.|
|`subdomain`|`string`|`www`<br>`@`<br>`api.stage`|The subdomain whose DNS record you want to update, not including `domain` or a trailing period. To update `domain` itself, set this to `@`. Can also be a multi-level subdomain.|
|`updateInterval`|`TimeSpan`|`0.00:05:00`|How frequently this program will check if your public IP address has changed and update DNS. Format is `d.hh:mm:ss`.<br>**One-shot mode:** if set to `0:0:0` or negative, this program will exit after the first update attempt, instead of remaining running and updating periodically; useful if you want to trigger it yourself, like with `cron`.|
|`dnsRecordTimeToLive`|`TimeSpan`|`0.00:05:00`|How long DNS resolvers can cache your record before they must look it up again. Gandi requires this to be between 5 minutes and 30 days, inclusive.|
|`dryRun`|`bool`|`false`<br>`true`|Set to `false` to run normally, or `true` to avoid changing any DNS records.|
|`gandiApiKey`|`string`|`abcdefg`|Generate an API key under [Developer access](https://account.gandi.net/en/users/_/security) in your [Gandi Account](https://account.gandi.net/en). Personal Access Tokens are unfortunately not supported by [G6.GandiLiveDns](https://github.com/gaylord-roger/G6.GandiLiveDns).|
|`domain`|`string`|`example.com`<br>`example.co.uk`|The second-level domain name that you registered, including the TLD.|
|`subdomain`|`string`|`www`<br>`@`<br>`api.stage`|The subdomain whose DNS record you want to update, not including `domain` or a trailing period. To update `domain` itself, set this to `@` (default). Can also be a multi-level subdomain.|
|`updateInterval`|`TimeSpan`|`0.00:05:00`|How frequently this program will check if your public IP address has changed and update DNS. Format is `d.hh:mm:ss`. Defaults to 5 minutes.<br>**One-shot mode:** if set to `0:0:0` or negative, this program will exit after the first update attempt, instead of remaining running and updating periodically; useful if you want to trigger it yourself, like with `cron`.|
|`dnsRecordTimeToLive`|`TimeSpan`|`0.00:05:00`|How long DNS resolvers can cache your record before they must look it up again. Gandi requires this to be between 5 minutes and 30 days, inclusive. Defaults to 5 minutes.|
|`dryRun`|`bool`|`false`<br>`true`|Set to `false` (default) to run normally, or `true` to avoid changing any DNS records.|
|`stunServerBlacklist`|`string[]`|`["stun.bergophor.de", "stun.usfamily.net"]`|List of STUN server hostnames to not use when determining your computer's public IP address. Defaults to blocking `stun.bergophor.de` and `stun.usfamily.net` due to incorrect responses.|

## Execution
- **Manually**: `./GandiDynamicDns`
Expand Down
16 changes: 12 additions & 4 deletions Tests/DynamicDnsServiceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ public class DynamicDnsServiceTest {
[Fact]
public async Task updateRecord() {
A.CallTo(() => dns.fetchDnsRecords(A<string>._, A<string>._, A<DnsRecordType>._, A<CancellationToken>._)).Returns(["192.0.2.1"]);
A.CallTo(() => stun.getSelfWanAddress(A<CancellationToken>._)).Returns(new SelfWanAddressResponse(IPAddress.Parse("192.0.2.2"), IPEndPoint.Parse("192.0.2.3")));
A.CallTo(() => stun.getSelfWanAddress(A<CancellationToken>._))
.Returns(new SelfWanAddressResponse(IPAddress.Parse("192.0.2.2"), new DnsEndPoint("example.com", 3478), IPEndPoint.Parse("192.0.2.3")));

await service.StartAsync(default);
await service.ExecuteTask!;
Expand All @@ -45,7 +46,8 @@ public class DynamicDnsServiceTest {
[Fact]
public async Task invalidExistingRecord() {
A.CallTo(() => dns.fetchDnsRecords(A<string>._, A<string>._, A<DnsRecordType>._, A<CancellationToken>._)).Returns(["hargle"]);
A.CallTo(() => stun.getSelfWanAddress(A<CancellationToken>._)).Returns(new SelfWanAddressResponse(IPAddress.Parse("192.0.2.2"), IPEndPoint.Parse("192.0.2.3")));
A.CallTo(() => stun.getSelfWanAddress(A<CancellationToken>._))
.Returns(new SelfWanAddressResponse(IPAddress.Parse("192.0.2.2"), new DnsEndPoint("example.com", 3478), IPEndPoint.Parse("192.0.2.3")));

await service.StartAsync(default);
await service.ExecuteTask!;
Expand All @@ -60,7 +62,8 @@ public class DynamicDnsServiceTest {
[Fact]
public async Task unchanged() {
A.CallTo(() => dns.fetchDnsRecords(A<string>._, A<string>._, A<DnsRecordType>._, A<CancellationToken>._)).Returns(["192.0.2.1"]);
A.CallTo(() => stun.getSelfWanAddress(A<CancellationToken>._)).Returns(new SelfWanAddressResponse(IPAddress.Parse("192.0.2.1"), IPEndPoint.Parse("192.0.2.3")));
A.CallTo(() => stun.getSelfWanAddress(A<CancellationToken>._))
.Returns(new SelfWanAddressResponse(IPAddress.Parse("192.0.2.1"), new DnsEndPoint("example.com", 3478), IPEndPoint.Parse("192.0.2.3")));

await service.StartAsync(default);
await service.ExecuteTask!;
Expand Down Expand Up @@ -93,7 +96,7 @@ public class DynamicDnsServiceTest {
latch.Signal();
} catch (InvalidOperationException) { }
})
.Returns(new SelfWanAddressResponse(IPAddress.Parse("192.0.2.2"), IPEndPoint.Parse("192.0.2.3")));
.Returns(new SelfWanAddressResponse(IPAddress.Parse("192.0.2.2"), new DnsEndPoint("example.com", 3478), IPEndPoint.Parse("192.0.2.3")));

await service.StartAsync(cts.Token);
latch.Wait(10_000);
Expand All @@ -109,4 +112,9 @@ public class DynamicDnsServiceTest {
A.CallTo(() => lifetime.StopApplication()).MustNotHaveHappened();
}

[Fact]
public void disposal() {
service.Dispose();
}

}
17 changes: 12 additions & 5 deletions Tests/Net/Stun/MultiServerStunClientTest.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using GandiDynamicDns.Net.Stun;
using GandiDynamicDns;
using GandiDynamicDns.Net.Stun;
using GandiDynamicDns.Unfucked.Stun;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Options;
using STUN.Enums;
using STUN.Proxy;
using STUN.StunResult;
using System.Net;
using Tests.Mocks;
Expand All @@ -18,9 +19,15 @@ public class MultiServerStunClientTest: IDisposable {

public MultiServerStunClientTest() {
MultiServerStunClient.SERVERS_CACHE.Clear();
multiServerStunClient = new MultiServerStunClient(new HttpClient(httpMessageHandler), stunClientFactory, new NullLogger<MultiServerStunClient>());

A.CallTo(() => stunClientFactory.createStunClient(A<IPEndPoint>._, A<IPEndPoint>._, A<IUdpProxy>._)).Returns(singleServerStunClient);
multiServerStunClient = new MultiServerStunClient(new HttpClient(httpMessageHandler), stunClientFactory, new NullLogger<MultiServerStunClient>(), new OptionsWrapper<Configuration>(
new Configuration {
gandiApiKey = "",
domain = "example.com"
}));

A.CallTo(() => stunClientFactory.createStunClient(A<DnsEndPoint>._)).Returns(singleServerStunClient);
A.CallTo(() => singleServerStunClient.Server).Returns(new DnsEndPoint("example.com", 3478));
A.CallTo(() => singleServerStunClient.ServerAddress).Returns(IPEndPoint.Parse("192.0.2.1:12345"));

A.CallTo(() => httpMessageHandler.fakeSendAsync(A<HttpRequestMessage>._, A<CancellationToken>._))
.Returns(new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent("192.0.2.1:12345\n192.0.2.2:12345\n192.0.2.3:hargle\n") });
Expand Down
2 changes: 1 addition & 1 deletion Tests/Tests.runsettings
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<!-- Exclusion rules are not synchronized with dotCover, which are controlled by *.sln.DotSettings -->
<!-- Syntax: https://github.com/coverlet-coverage/coverlet/blob/master/Documentation/MSBuildIntegration.md#filters -->
<Exclude>[Test*]*,[GandiDynamicDns]GandiDynamicDns.Unfucked.*</Exclude>
<Exclude>[Test*]*,[StunDnsResolver]*,[GandiDynamicDns]GandiDynamicDns.Unfucked.*</Exclude>
</Configuration>
</DataCollector>
</DataCollectors>
Expand Down

0 comments on commit 75eb691

Please sign in to comment.