|
| 1 | +using E4A.PostGuard; |
| 2 | + |
| 3 | +namespace E4A.PostGuard.Tests; |
| 4 | + |
| 5 | +public class PostGuardConfigTests |
| 6 | +{ |
| 7 | + private const string ValidPkg = "https://pkg.postguard.eu"; |
| 8 | + private const string ValidCryptify = "https://cryptify.postguard.eu"; |
| 9 | + |
| 10 | + [Fact] |
| 11 | + public void Ctor_AcceptsHttpsUrls() |
| 12 | + { |
| 13 | + var config = new PostGuardConfig |
| 14 | + { |
| 15 | + PkgUrl = ValidPkg, |
| 16 | + CryptifyUrl = ValidCryptify, |
| 17 | + }; |
| 18 | + |
| 19 | + var pg = new PostGuard(config); |
| 20 | + |
| 21 | + Assert.NotNull(pg); |
| 22 | + } |
| 23 | + |
| 24 | + [Theory] |
| 25 | + [InlineData("http://pkg.postguard.eu")] |
| 26 | + [InlineData("http://localhost:8080")] |
| 27 | + [InlineData("ftp://pkg.postguard.eu")] |
| 28 | + [InlineData("pkg.postguard.eu")] |
| 29 | + [InlineData("/relative/path")] |
| 30 | + [InlineData("")] |
| 31 | + public void Ctor_RejectsNonHttpsPkgUrl(string badUrl) |
| 32 | + { |
| 33 | + var config = new PostGuardConfig |
| 34 | + { |
| 35 | + PkgUrl = badUrl, |
| 36 | + CryptifyUrl = ValidCryptify, |
| 37 | + }; |
| 38 | + |
| 39 | + var ex = Assert.Throws<ArgumentException>(() => new PostGuard(config)); |
| 40 | + Assert.Equal("PkgUrl", ex.ParamName); |
| 41 | + } |
| 42 | + |
| 43 | + [Theory] |
| 44 | + [InlineData("http://cryptify.postguard.eu")] |
| 45 | + [InlineData("ws://cryptify.postguard.eu")] |
| 46 | + [InlineData("cryptify.postguard.eu")] |
| 47 | + public void Ctor_RejectsNonHttpsCryptifyUrl(string badUrl) |
| 48 | + { |
| 49 | + var config = new PostGuardConfig |
| 50 | + { |
| 51 | + PkgUrl = ValidPkg, |
| 52 | + CryptifyUrl = badUrl, |
| 53 | + }; |
| 54 | + |
| 55 | + var ex = Assert.Throws<ArgumentException>(() => new PostGuard(config)); |
| 56 | + Assert.Equal("CryptifyUrl", ex.ParamName); |
| 57 | + } |
| 58 | + |
| 59 | + [Fact] |
| 60 | + public void Ctor_AllowInsecureUrls_AcceptsHttpLocalhost() |
| 61 | + { |
| 62 | + var config = new PostGuardConfig |
| 63 | + { |
| 64 | + PkgUrl = "http://localhost:8080", |
| 65 | + CryptifyUrl = "http://localhost:8081", |
| 66 | + AllowInsecureUrls = true, |
| 67 | + }; |
| 68 | + |
| 69 | + var pg = new PostGuard(config); |
| 70 | + |
| 71 | + Assert.NotNull(pg); |
| 72 | + } |
| 73 | + |
| 74 | + [Fact] |
| 75 | + public void Ctor_AllowInsecureUrls_StillAcceptsHttpsUrls() |
| 76 | + { |
| 77 | + var config = new PostGuardConfig |
| 78 | + { |
| 79 | + PkgUrl = ValidPkg, |
| 80 | + CryptifyUrl = ValidCryptify, |
| 81 | + AllowInsecureUrls = true, |
| 82 | + }; |
| 83 | + |
| 84 | + var pg = new PostGuard(config); |
| 85 | + |
| 86 | + Assert.NotNull(pg); |
| 87 | + } |
| 88 | + |
| 89 | + [Fact] |
| 90 | + public void Ctor_NullConfig_Throws() |
| 91 | + { |
| 92 | + Assert.Throws<ArgumentNullException>(() => new PostGuard(null!)); |
| 93 | + } |
| 94 | +} |
0 commit comments