Skip to content

Commit 6589fe6

Browse files
authored
Merge pull request #100 from domainr/frnic-extension
Add support for the Afnic frnic-2.0 extension
2 parents 2befae6 + 8625ad7 commit 6589fe6

File tree

5 files changed

+129
-0
lines changed

5 files changed

+129
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.DS_Store
22
sample.xml
33
.aider*
4+
local/*

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.PHONY: test
2+
test:
3+
go test -v ./...

check.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,4 +481,30 @@ func init() {
481481

482482
return nil
483483
})
484+
485+
// Scan frnic-2.0 extension for reserved/forbidden attributes
486+
path = "epp > response > extension > " + ExtFrnic20 + " ext > resData > chkData > domain > cd > name"
487+
scanResponse.MustHandleCharData(path, func(c *xx.Context) error {
488+
dcr := &c.Value.(*Response).DomainCheckResponse
489+
490+
// Read the reserved attribute and store it as a charge category
491+
if c.AttrBool("", "reserved") {
492+
charge := DomainCharge{
493+
Domain: string(c.CharData), // domain name from element text
494+
Category: "reserved",
495+
}
496+
dcr.Charges = append(dcr.Charges, charge)
497+
}
498+
499+
// Optionally handle forbidden attribute
500+
if c.AttrBool("", "forbidden") {
501+
charge := DomainCharge{
502+
Domain: string(c.CharData),
503+
Category: "forbidden",
504+
}
505+
dcr.Charges = append(dcr.Charges, charge)
506+
}
507+
508+
return nil
509+
})
484510
}

check_test.go

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,103 @@ func TestScanCheckDomainResponsePriceExtension(t *testing.T) {
774774
st.Expect(t, dcr.Charges[0].CategoryName, "")
775775
}
776776

777+
func TestScanCheckDomainResponseFrnicExtension(t *testing.T) {
778+
x := `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
779+
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0" xmlns:domain="urn:ietf:params:xml:ns:domain-1.0" xmlns:frnic="http://www.afnic.fr/xml/epp/frnic-2.0">
780+
<response>
781+
<result code="1000">
782+
<msg>Command completed successfully</msg>
783+
</result>
784+
<resData>
785+
<domain:chkData>
786+
<domain:cd>
787+
<domain:name avail="1">frety.fr</domain:name>
788+
</domain:cd>
789+
</domain:chkData>
790+
</resData>
791+
<extension>
792+
<frnic:ext>
793+
<frnic:resData>
794+
<frnic:chkData>
795+
<frnic:domain>
796+
<frnic:cd>
797+
<frnic:name forbidden="0" reserved="1">frety.fr</frnic:name>
798+
<frnic:rsvReason>City name</frnic:rsvReason>
799+
</frnic:cd>
800+
</frnic:domain>
801+
</frnic:chkData>
802+
</frnic:resData>
803+
</frnic:ext>
804+
</extension>
805+
<trID>
806+
<svTRID>EPP-8da5fca0-1cf7-4178-9813-82b3d892ebad</svTRID>
807+
</trID>
808+
</response>
809+
</epp>`
810+
811+
var res Response
812+
dcr := &res.DomainCheckResponse
813+
814+
d := decoder(x)
815+
err := IgnoreEOF(scanResponse.Scan(d, &res))
816+
st.Expect(t, err, nil)
817+
st.Expect(t, len(dcr.Checks), 1)
818+
st.Expect(t, dcr.Checks[0].Domain, "frety.fr")
819+
st.Expect(t, dcr.Checks[0].Available, true)
820+
st.Expect(t, len(dcr.Charges), 1)
821+
st.Expect(t, dcr.Charges[0].Domain, "frety.fr")
822+
st.Expect(t, dcr.Charges[0].Category, "reserved")
823+
st.Expect(t, dcr.Charges[0].CategoryName, "")
824+
}
825+
826+
func TestScanCheckDomainResponseFrnicExtensionForbidden(t *testing.T) {
827+
x := `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
828+
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0" xmlns:domain="urn:ietf:params:xml:ns:domain-1.0" xmlns:frnic="http://www.afnic.fr/xml/epp/frnic-2.0">
829+
<response>
830+
<result code="1000">
831+
<msg>Command completed successfully</msg>
832+
</result>
833+
<resData>
834+
<domain:chkData>
835+
<domain:cd>
836+
<domain:name avail="0">forbidden-test.fr</domain:name>
837+
</domain:cd>
838+
</domain:chkData>
839+
</resData>
840+
<extension>
841+
<frnic:ext>
842+
<frnic:resData>
843+
<frnic:chkData>
844+
<frnic:domain>
845+
<frnic:cd>
846+
<frnic:name forbidden="1" reserved="0">forbidden-test.fr</frnic:name>
847+
</frnic:cd>
848+
</frnic:domain>
849+
</frnic:chkData>
850+
</frnic:resData>
851+
</frnic:ext>
852+
</extension>
853+
<trID>
854+
<svTRID>EPP-test-forbidden</svTRID>
855+
</trID>
856+
</response>
857+
</epp>`
858+
859+
var res Response
860+
dcr := &res.DomainCheckResponse
861+
862+
d := decoder(x)
863+
err := IgnoreEOF(scanResponse.Scan(d, &res))
864+
st.Expect(t, err, nil)
865+
st.Expect(t, len(dcr.Checks), 1)
866+
st.Expect(t, dcr.Checks[0].Domain, "forbidden-test.fr")
867+
st.Expect(t, dcr.Checks[0].Available, false)
868+
st.Expect(t, len(dcr.Charges), 1)
869+
st.Expect(t, dcr.Charges[0].Domain, "forbidden-test.fr")
870+
st.Expect(t, dcr.Charges[0].Category, "forbidden")
871+
st.Expect(t, dcr.Charges[0].CategoryName, "")
872+
}
873+
777874
func BenchmarkEncodeDomainCheck(b *testing.B) {
778875
domains := []string{"hello.com"}
779876
for i := 0; i < b.N; i++ {

greeting.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ const (
7979
ExtNamestore = "http://www.verisign-grs.com/epp/namestoreExt-1.1"
8080
ExtNeulevel = "urn:ietf:params:xml:ns:neulevel"
8181
ExtNeulevel10 = "urn:ietf:params:xml:ns:neulevel-1.0"
82+
ExtFrnic20 = "http://www.afnic.fr/xml/epp/frnic-2.0"
8283
)
8384

8485
// ExtURNNames maps short extension names to their full URN.
@@ -100,6 +101,7 @@ var ExtURNNames = map[string]string{
100101
"namestoreExt-1.1": ExtNamestore,
101102
"neulevel": ExtNeulevel,
102103
"neulevel-1.0": ExtNeulevel10,
104+
"frnic-2.0": ExtFrnic20,
103105
}
104106

105107
// TODO: check if res.Greeting is not empty.

0 commit comments

Comments
 (0)