| 104 CX_TEST_ASSERT(!strcasecmp(test, str2_enc_expected)); |
104 CX_TEST_ASSERT(!strcasecmp(test, str2_enc_expected)); |
| 105 |
105 |
| 106 } |
106 } |
| 107 } |
107 } |
| 108 |
108 |
| |
109 CX_TEST(test_util_parse_uri) { |
| |
110 CX_TEST_DO { |
| |
111 WSUri uri; |
| |
112 CX_TEST_ASSERT(util_parse_uri("http://example.com", &uri)); |
| |
113 CX_TEST_ASSERT(!cx_strcmp(cx_strn(uri.host, uri.hostlen), "example.com")); |
| |
114 CX_TEST_ASSERT(!cx_strcmp(cx_strn(uri.scheme, uri.schemelen), "http")); |
| |
115 CX_TEST_ASSERT(uri.pathlen == 0); |
| |
116 CX_TEST_ASSERT(uri.scheme_num == WS_URI_HTTP); |
| |
117 CX_TEST_ASSERT(uri.port == 80); |
| |
118 |
| |
119 CX_TEST_ASSERT(util_parse_uri("https://unixwork.de/path/", &uri)); |
| |
120 CX_TEST_ASSERT(!cx_strcmp(cx_strn(uri.host, uri.hostlen), "unixwork.de")); |
| |
121 CX_TEST_ASSERT(!cx_strcmp(cx_strn(uri.scheme, uri.schemelen), "https")); |
| |
122 CX_TEST_ASSERT(!cx_strcmp(cx_strn(uri.path, uri.pathlen), "/path/")); |
| |
123 CX_TEST_ASSERT(uri.scheme_num == WS_URI_HTTPS); |
| |
124 CX_TEST_ASSERT(uri.port == 443); |
| |
125 |
| |
126 CX_TEST_ASSERT(util_parse_uri("https://code.unixwork.de/", &uri)); |
| |
127 CX_TEST_ASSERT(!cx_strcmp(cx_strn(uri.host, uri.hostlen), "code.unixwork.de")); |
| |
128 CX_TEST_ASSERT(!cx_strcmp(cx_strn(uri.scheme, uri.schemelen), "https")); |
| |
129 CX_TEST_ASSERT(!cx_strcmp(cx_strn(uri.path, uri.pathlen), "/")); |
| |
130 CX_TEST_ASSERT(uri.scheme_num == WS_URI_HTTPS); |
| |
131 |
| |
132 CX_TEST_ASSERT(util_parse_uri("http://pkg.unixwork.de:8080", &uri)); |
| |
133 CX_TEST_ASSERT(!cx_strcmp(cx_strn(uri.host, uri.hostlen), "pkg.unixwork.de")); |
| |
134 CX_TEST_ASSERT(!cx_strcmp(cx_strn(uri.scheme, uri.schemelen), "http")); |
| |
135 CX_TEST_ASSERT(!cx_strcmp(cx_strn(uri.path, uri.pathlen), "")); |
| |
136 CX_TEST_ASSERT(uri.port == 8080); |
| |
137 CX_TEST_ASSERT(uri.scheme_num == WS_URI_HTTP); |
| |
138 |
| |
139 CX_TEST_ASSERT(util_parse_uri("https://pkg.unixwork.eu:8443/", &uri)); |
| |
140 CX_TEST_ASSERT(!cx_strcmp(cx_strn(uri.host, uri.hostlen), "pkg.unixwork.eu")); |
| |
141 CX_TEST_ASSERT(!cx_strcmp(cx_strn(uri.scheme, uri.schemelen), "https")); |
| |
142 CX_TEST_ASSERT(!cx_strcmp(cx_strn(uri.path, uri.pathlen), "/")); |
| |
143 CX_TEST_ASSERT(uri.port == 8443); |
| |
144 CX_TEST_ASSERT(uri.scheme_num == WS_URI_HTTPS); |
| |
145 |
| |
146 CX_TEST_ASSERT(util_parse_uri("http://[::1]", &uri)); |
| |
147 CX_TEST_ASSERT(!cx_strcmp(cx_strn(uri.host, uri.hostlen), "::1")); |
| |
148 CX_TEST_ASSERT(!cx_strcmp(cx_strn(uri.scheme, uri.schemelen), "http")); |
| |
149 CX_TEST_ASSERT(!cx_strcmp(cx_strn(uri.path, uri.pathlen), "")); |
| |
150 CX_TEST_ASSERT(uri.port == 80); |
| |
151 CX_TEST_ASSERT(uri.scheme_num == WS_URI_HTTP); |
| |
152 |
| |
153 CX_TEST_ASSERT(util_parse_uri("http://[fe80::1ff:fe23:4567:890a]:8081", &uri)); |
| |
154 CX_TEST_ASSERT(!cx_strcmp(cx_strn(uri.host, uri.hostlen), "fe80::1ff:fe23:4567:890a")); |
| |
155 CX_TEST_ASSERT(!cx_strcmp(cx_strn(uri.scheme, uri.schemelen), "http")); |
| |
156 CX_TEST_ASSERT(!cx_strcmp(cx_strn(uri.path, uri.pathlen), "")); |
| |
157 CX_TEST_ASSERT(uri.port == 8081); |
| |
158 CX_TEST_ASSERT(uri.scheme_num == WS_URI_HTTP); |
| |
159 |
| |
160 CX_TEST_ASSERT(util_parse_uri("http://[::ffff:0.0.0.0]:8082/ipv6/path/", &uri)); |
| |
161 CX_TEST_ASSERT(!cx_strcmp(cx_strn(uri.host, uri.hostlen), "::ffff:0.0.0.0")); |
| |
162 CX_TEST_ASSERT(!cx_strcmp(cx_strn(uri.scheme, uri.schemelen), "http")); |
| |
163 CX_TEST_ASSERT(!cx_strcmp(cx_strn(uri.path, uri.pathlen), "/ipv6/path/")); |
| |
164 CX_TEST_ASSERT(uri.port == 8082); |
| |
165 CX_TEST_ASSERT(uri.scheme_num == WS_URI_HTTP); |
| |
166 |
| |
167 CX_TEST_ASSERT(util_parse_uri("http://[::ffff:0.0.0.1]/ipv6/without/port/", &uri)); |
| |
168 CX_TEST_ASSERT(!cx_strcmp(cx_strn(uri.host, uri.hostlen), "::ffff:0.0.0.1")); |
| |
169 CX_TEST_ASSERT(!cx_strcmp(cx_strn(uri.scheme, uri.schemelen), "http")); |
| |
170 CX_TEST_ASSERT(!cx_strcmp(cx_strn(uri.path, uri.pathlen), "/ipv6/without/port/")); |
| |
171 CX_TEST_ASSERT(uri.port == 80); |
| |
172 CX_TEST_ASSERT(uri.scheme_num == WS_URI_HTTP); |
| |
173 } |
| |
174 } |
| |
175 |
| |
176 CX_TEST(test_util_parse_uri_error) { |
| |
177 CX_TEST_DO { |
| |
178 WSUri uri; |
| |
179 CX_TEST_ASSERT(!util_parse_uri("", &uri)); |
| |
180 CX_TEST_ASSERT(!util_parse_uri("http", &uri)); |
| |
181 CX_TEST_ASSERT(!util_parse_uri("https://", &uri)); |
| |
182 CX_TEST_ASSERT(!util_parse_uri("http://host:invalidport", &uri)); |
| |
183 CX_TEST_ASSERT(!util_parse_uri("http://host:01:02", &uri)); |
| |
184 CX_TEST_ASSERT(!util_parse_uri("http:///", &uri)); |
| |
185 CX_TEST_ASSERT(!util_parse_uri("http://[::1", &uri)); |
| |
186 CX_TEST_ASSERT(!util_parse_uri("http://[::1]test", &uri)); |
| |
187 CX_TEST_ASSERT(!util_parse_uri("http://[:[:1]", &uri)); |
| |
188 CX_TEST_ASSERT(!util_parse_uri("http://[hello-world]", &uri)); |
| |
189 CX_TEST_ASSERT(!util_parse_uri("http://host[]", &uri)); |
| |
190 CX_TEST_ASSERT(!util_parse_uri("http://localhost:9999999", &uri)); |
| |
191 } |
| |
192 } |