|
| 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 | +} |
0 commit comments