Skip to content

Commit cb37df3

Browse files
committed
test(contact): add e2e create-contact coverage and refactor login payload reuse
1 parent 7a99486 commit cb37df3

File tree

7 files changed

+180
-100
lines changed

7 files changed

+180
-100
lines changed

internal/model/contact.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ type Disclose struct {
1717
}
1818

1919
type ContactCreateInput struct {
20-
Disclose *Disclose
20+
Disclose *Disclose `json:",inline"`
2121
ContactID string
2222
Name string
2323
Organization string

internal/repository/contact/create.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ INSERT INTO contacts (
4141
fax,
4242
auth_info_hash,
4343
disclose
44-
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9::jsonb)
44+
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)
4545
RETURNING id
4646
`
4747
var disclose any = struct{}{}

internal/service/contact/create.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func (s *Service) Create(
9595
resp = response.NewResponse[ContactCreateResData, struct{}](code, code.String()).
9696
WithResData(data)
9797

98-
s.log.WithUserId(registrarId).Info("contact %s created", contactId)
98+
s.log.WithUserId(registrarId).Info("contact %d created", contactId)
9999

100100
return resp
101101
}

tests/contact_test.go

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
package tests
2+
3+
import (
4+
"crypto/tls"
5+
"testing"
6+
"time"
7+
8+
"github.com/stretchr/testify/assert"
9+
"github.com/stretchr/testify/require"
10+
)
11+
12+
func TestCreateContactSuccess(t *testing.T) {
13+
addr := netAddr()
14+
conn, err := tls.Dial("tcp", addr, &tls.Config{
15+
MinVersion: tls.VersionTLS12,
16+
InsecureSkipVerify: true, //nolint:gosec
17+
})
18+
19+
require.NoError(t, err)
20+
21+
_ = conn.SetDeadline(time.Now().Add(10 * time.Second))
22+
_, _ = readEPPFrame(conn)
23+
24+
payload := loginXML()
25+
26+
err = writeEPPFrame(conn, []byte(payload))
27+
require.NoError(t, err)
28+
29+
resp, err := readEPPFrame(conn)
30+
require.NoError(t, err)
31+
32+
assert.Contains(t, string(resp), "Command completed successfully")
33+
34+
payload = `
35+
<?xml version="1.0" encoding="UTF-8"?>
36+
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
37+
<command>
38+
<create>
39+
<contact:create xmlns:contact="urn:ietf:params:xml:ns:contact-1.0">
40+
<contact:id>identifier</contact:id>
41+
42+
<contact:postalInfo type="int">
43+
<contact:name>John Doe</contact:name>
44+
<contact:org>Example Inc.</contact:org>
45+
<contact:addr>
46+
<contact:street>123 Example Dr.</contact:street>
47+
<contact:street>Suite 100</contact:street>
48+
<contact:city>Dulles</contact:city>
49+
<contact:sp>VA</contact:sp>
50+
<contact:pc>20166-6503</contact:pc>
51+
<contact:cc>US</contact:cc>
52+
</contact:addr>
53+
</contact:postalInfo>
54+
55+
<contact:postalInfo type="loc">
56+
<contact:name>John Doe</contact:name>
57+
<contact:org>Example LLC.</contact:org>
58+
<contact:addr>
59+
<contact:street>Example str.</contact:street>
60+
<contact:city>NY</contact:city>
61+
<contact:cc>US</contact:cc>
62+
</contact:addr>
63+
</contact:postalInfo>
64+
65+
<contact:voice x="123">+1.7035555555</contact:voice>
66+
<contact:fax>+1.7035555556</contact:fax>
67+
<contact:email>jdoe@example.com</contact:email>
68+
69+
<contact:authInfo>
70+
<contact:pw>password</contact:pw>
71+
</contact:authInfo>
72+
73+
<contact:disclose flag="0">
74+
<contact:voice/>
75+
<contact:email/>
76+
<contact:addr type="int"/>
77+
</contact:disclose>
78+
</contact:create>
79+
</create>
80+
<clTRID>CONTACT-CREATE-VALID-FULL</clTRID>
81+
</command>
82+
</epp>
83+
`
84+
85+
err = writeEPPFrame(conn, []byte(payload))
86+
require.NoError(t, err)
87+
88+
resp, err = readEPPFrame(conn)
89+
require.NoError(t, err)
90+
91+
assert.Contains(t, string(resp), "Command completed successfully")
92+
93+
t.Cleanup(func() {
94+
_ = conn.Close()
95+
})
96+
}
97+
98+
func TestCreateInvalidScheme(t *testing.T) {
99+
addr := netAddr()
100+
conn, err := tls.Dial("tcp", addr, &tls.Config{
101+
MinVersion: tls.VersionTLS12,
102+
InsecureSkipVerify: true, //nolint:gosec
103+
})
104+
105+
require.NoError(t, err)
106+
107+
_ = conn.SetDeadline(time.Now().Add(10 * time.Second))
108+
_, _ = readEPPFrame(conn)
109+
110+
payload := loginXML()
111+
112+
err = writeEPPFrame(conn, []byte(payload))
113+
require.NoError(t, err)
114+
115+
resp, err := readEPPFrame(conn)
116+
require.NoError(t, err)
117+
118+
assert.Contains(t, string(resp), "Command completed successfully")
119+
120+
payload = `
121+
<?xml version="1.0" encoding="UTF-8"?>
122+
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
123+
<command>
124+
<create>
125+
<contact:create xmlns:contact="urn:ietf:params:xml:ns:contact-1.0">
126+
</contact:create>
127+
</create>
128+
<clTRID>CONTACT-CREATE-VALID-FULL</clTRID>
129+
</command>
130+
</epp>
131+
`
132+
133+
err = writeEPPFrame(conn, []byte(payload))
134+
require.NoError(t, err)
135+
136+
resp, err = readEPPFrame(conn)
137+
require.NoError(t, err)
138+
139+
assert.Contains(t, string(resp), "Command syntax error")
140+
141+
t.Cleanup(func() {
142+
_ = conn.Close()
143+
})
144+
}

tests/helpers_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,32 @@ func readEPPFrame(r io.Reader) ([]byte, error) {
9191

9292
return payload, nil
9393
}
94+
95+
func loginXML() string {
96+
payload := fmt.Sprintf(`
97+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
98+
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
99+
<command>
100+
<login>
101+
<clID>%s</clID>
102+
<pw>%s</pw>
103+
<options>
104+
<version>1.0</version>
105+
<lang>en</lang>
106+
</options>
107+
<svcs>
108+
<objURI>urn:ietf:params:xml:ns:obj1</objURI>
109+
<objURI>urn:ietf:params:xml:ns:obj2</objURI>
110+
<objURI>urn:ietf:params:xml:ns:obj3</objURI>
111+
<svcExtension>
112+
<extURI>http://custom/obj1ext-1.0</extURI>
113+
</svcExtension>
114+
</svcs>
115+
</login>
116+
<clTRID>ABC-12345</clTRID>
117+
</command>
118+
</epp>
119+
`, testingRegistrarUsername, testingRegistrarPassword)
120+
121+
return payload
122+
}

tests/login_test.go

Lines changed: 3 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -73,30 +73,7 @@ func TestLoginValidCredentials(t *testing.T) {
7373
_ = conn.SetDeadline(time.Now().Add(10 * time.Second))
7474
_, _ = readEPPFrame(conn)
7575

76-
payload := fmt.Sprintf(`
77-
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
78-
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
79-
<command>
80-
<login>
81-
<clID>%s</clID>
82-
<pw>%s</pw>
83-
<options>
84-
<version>1.0</version>
85-
<lang>en</lang>
86-
</options>
87-
<svcs>
88-
<objURI>urn:ietf:params:xml:ns:obj1</objURI>
89-
<objURI>urn:ietf:params:xml:ns:obj2</objURI>
90-
<objURI>urn:ietf:params:xml:ns:obj3</objURI>
91-
<svcExtension>
92-
<extURI>http://custom/obj1ext-1.0</extURI>
93-
</svcExtension>
94-
</svcs>
95-
</login>
96-
<clTRID>ABC-12345</clTRID>
97-
</command>
98-
</epp>
99-
`, testingRegistrarUsername, testingRegistrarPassword)
76+
payload := loginXML()
10077

10178
err = writeEPPFrame(conn, []byte(payload))
10279
require.NoError(t, err)
@@ -123,30 +100,7 @@ func TestAlreadyLoggedIn(t *testing.T) {
123100
_ = conn.SetDeadline(time.Now().Add(10 * time.Second))
124101
_, _ = readEPPFrame(conn)
125102

126-
payload := fmt.Sprintf(`
127-
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
128-
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
129-
<command>
130-
<login>
131-
<clID>%s</clID>
132-
<pw>%s</pw>
133-
<options>
134-
<version>1.0</version>
135-
<lang>en</lang>
136-
</options>
137-
<svcs>
138-
<objURI>urn:ietf:params:xml:ns:obj1</objURI>
139-
<objURI>urn:ietf:params:xml:ns:obj2</objURI>
140-
<objURI>urn:ietf:params:xml:ns:obj3</objURI>
141-
<svcExtension>
142-
<extURI>http://custom/obj1ext-1.0</extURI>
143-
</svcExtension>
144-
</svcs>
145-
</login>
146-
<clTRID>ABC-12345</clTRID>
147-
</command>
148-
</epp>
149-
`, testingRegistrarUsername, testingRegistrarPassword)
103+
payload := loginXML()
150104

151105
err = writeEPPFrame(conn, []byte(payload))
152106
require.NoError(t, err)
@@ -156,30 +110,7 @@ func TestAlreadyLoggedIn(t *testing.T) {
156110

157111
assert.Contains(t, string(resp), "Command completed successfully")
158112

159-
payload = fmt.Sprintf(`
160-
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
161-
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
162-
<command>
163-
<login>
164-
<clID>%s</clID>
165-
<pw>%s</pw>
166-
<options>
167-
<version>1.0</version>
168-
<lang>en</lang>
169-
</options>
170-
<svcs>
171-
<objURI>urn:ietf:params:xml:ns:obj1</objURI>
172-
<objURI>urn:ietf:params:xml:ns:obj2</objURI>
173-
<objURI>urn:ietf:params:xml:ns:obj3</objURI>
174-
<svcExtension>
175-
<extURI>http://custom/obj1ext-1.0</extURI>
176-
</svcExtension>
177-
</svcs>
178-
</login>
179-
<clTRID>ABC-12345</clTRID>
180-
</command>
181-
</epp>
182-
`, testingRegistrarUsername, testingRegistrarPassword)
113+
payload = loginXML()
183114

184115
err = writeEPPFrame(conn, []byte(payload))
185116
require.NoError(t, err)

tests/logout_test.go

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package tests
22

33
import (
44
"crypto/tls"
5-
"fmt"
65
"testing"
76
"time"
87

@@ -22,30 +21,7 @@ func TestLogoutSuccess(t *testing.T) {
2221
_ = conn.SetDeadline(time.Now().Add(10 * time.Second))
2322
_, _ = readEPPFrame(conn)
2423

25-
payload := fmt.Sprintf(`
26-
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
27-
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
28-
<command>
29-
<login>
30-
<clID>%s</clID>
31-
<pw>%s</pw>
32-
<options>
33-
<version>1.0</version>
34-
<lang>en</lang>
35-
</options>
36-
<svcs>
37-
<objURI>urn:ietf:params:xml:ns:obj1</objURI>
38-
<objURI>urn:ietf:params:xml:ns:obj2</objURI>
39-
<objURI>urn:ietf:params:xml:ns:obj3</objURI>
40-
<svcExtension>
41-
<extURI>http://custom/obj1ext-1.0</extURI>
42-
</svcExtension>
43-
</svcs>
44-
</login>
45-
<clTRID>ABC-12345</clTRID>
46-
</command>
47-
</epp>
48-
`, testingRegistrarUsername, testingRegistrarPassword)
24+
payload := loginXML()
4925

5026
err = writeEPPFrame(conn, []byte(payload))
5127
require.NoError(t, err)

0 commit comments

Comments
 (0)