private void EditDns(DnsChallenge dnsChallenge, bool delete) { var dnsName = dnsChallenge.RecordName; var dnsValue = Regex.Replace(dnsChallenge.RecordValue, "\\s", ""); var dnsValues = Regex.Replace(dnsValue, "(.{100,100})", "$1\n").Split('\n'); var r53 = new Route53Helper { HostedZoneId = HostedZoneId, ResourceRecordTtl = ResourceRecordTtl, CommonParams = CommonParams, }; if (ResourceRecordType == "TXT") r53.EditTxtRecord(dnsName, dnsValues, delete); else throw new NotImplementedException($"RR type of [{ResourceRecordType}] not implemented"); }
public void TestHandlerDefineAndCleanUpResourceRecord() { var r = new Random(); var bn = new byte[4]; var bv = new byte[10]; r.NextBytes(bn); r.NextBytes(bv); var rn = BitConverter.ToString(bn); var rv = BitConverter.ToString(bv); var c = new DnsChallenge(AcmeProtocol.CHALLENGE_TYPE_DNS, new DnsChallengeAnswer()) { Token = "FOOBAR", RecordName = $"{rn}.{_handlerParams.DefaultDomain}", RecordValue = rv, }; var r53 = new Route53Helper { HostedZoneId = _handlerParams.HostedZoneId, }; r53.CommonParams.InitParams(_handlerParams); var p = GetProvider(); using (var h = p.GetHandler(c, _handlerParams)) { // Assert test record does *not* exist var rr = r53.GetRecords(c.RecordName); var rrFirst = rr.ResourceRecordSets.FirstOrDefault(x => x.Name.ToLower().StartsWith(c.RecordName.ToLower()))?.Name; Assert.IsNull(rrFirst); // Create the record... h.Handle(c); // ...and assert it does exist rr = r53.GetRecords(c.RecordName); rrFirst = rr.ResourceRecordSets.FirstOrDefault(x => x.Name.ToLower().StartsWith(c.RecordName.ToLower()))?.Name; Assert.IsNotNull(rrFirst); StringAssert.StartsWith(rrFirst.ToLower(), c.RecordName.ToLower()); // Clean up the record... h.CleanUp(c); // ...and assert it does not exist once more rr = r53.GetRecords(c.RecordName); rrFirst = rr.ResourceRecordSets.FirstOrDefault(x => x.Name.ToLower().StartsWith(c.RecordName.ToLower()))?.Name; Assert.IsNull(rrFirst); } }