url: introduce git_net_url_parse_scp Provide a mechanism for parsing scp-style paths (eg `git@github.com:libgit2/libgit2` into the url form `ssh://git@github.com/libgit2/libgit2`.)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603
diff --git a/src/net.c b/src/net.c
index 79c3fcd..1d4a391 100644
--- a/src/net.c
+++ b/src/net.c
@@ -192,6 +192,195 @@ done:
return error;
}
+static int scp_invalid(const char *message)
+{
+ git_error_set(GIT_ERROR_NET, "invalid scp-style path: %s", message);
+ return GIT_EINVALIDSPEC;
+}
+
+static bool is_ipv6(const char *str)
+{
+ const char *c;
+ size_t colons = 0;
+
+ if (*str++ != '[')
+ return false;
+
+ for (c = str; *c; c++) {
+ if (*c == ':')
+ colons++;
+
+ if (*c == ']')
+ return (colons > 1);
+
+ if (*c != ':' &&
+ (*c < '0' || *c > '9') &&
+ (*c < 'a' || *c > 'f') &&
+ (*c < 'A' || *c > 'F'))
+ return false;
+ }
+
+ return false;
+}
+
+static bool has_at(const char *str)
+{
+ const char *c;
+
+ for (c = str; *c; c++) {
+ if (*c == '@')
+ return true;
+
+ if (*c == ':')
+ break;
+ }
+
+ return false;
+}
+
+int git_net_url_parse_scp(git_net_url *url, const char *given)
+{
+ const char *default_port = default_port_for_scheme("ssh");
+ const char *c, *user, *host, *port, *path = NULL;
+ size_t user_len = 0, host_len = 0, port_len = 0;
+ unsigned short bracket = 0;
+
+ enum {
+ NONE,
+ USER,
+ HOST_START, HOST, HOST_END,
+ IPV6, IPV6_END,
+ PORT_START, PORT, PORT_END,
+ PATH_START
+ } state = NONE;
+
+ memset(url, 0, sizeof(git_net_url));
+
+ for (c = given; *c && !path; c++) {
+ switch (state) {
+ case NONE:
+ switch (*c) {
+ case '@':
+ return scp_invalid("unexpected '@'");
+ case ':':
+ return scp_invalid("unexpected ':'");
+ case '[':
+ if (is_ipv6(c)) {
+ state = IPV6;
+ host = c;
+ } else if (bracket++ > 1) {
+ return scp_invalid("unexpected '['");
+ }
+ break;
+ default:
+ if (has_at(c)) {
+ state = USER;
+ user = c;
+ } else {
+ state = HOST;
+ host = c;
+ }
+ break;
+ }
+ break;
+
+ case USER:
+ if (*c == '@') {
+ user_len = (c - user);
+ state = HOST_START;
+ }
+ break;
+
+ case HOST_START:
+ state = (*c == '[') ? IPV6 : HOST;
+ host = c;
+ break;
+
+ case HOST:
+ if (*c == ':') {
+ host_len = (c - host);
+ state = bracket ? PORT_START : PATH_START;
+ } else if (*c == ']') {
+ if (bracket-- == 0)
+ return scp_invalid("unexpected ']'");
+
+ host_len = (c - host);
+ state = HOST_END;
+ }
+ break;
+
+ case HOST_END:
+ if (*c != ':')
+ return scp_invalid("unexpected character after hostname");
+ state = PATH_START;
+ break;
+
+ case IPV6:
+ if (*c == ']')
+ state = IPV6_END;
+ break;
+
+ case IPV6_END:
+ if (*c != ':')
+ return scp_invalid("unexpected character after ipv6 address");
+
+ host_len = (c - host);
+ state = bracket ? PORT_START : PATH_START;
+ break;
+
+ case PORT_START:
+ port = c;
+ state = PORT;
+ break;
+
+ case PORT:
+ if (*c == ']') {
+ if (bracket-- == 0)
+ return scp_invalid("unexpected ']'");
+
+ port_len = c - port;
+ state = PORT_END;
+ }
+ break;
+
+ case PORT_END:
+ if (*c != ':')
+ return scp_invalid("unexpected character after ipv6 address");
+
+ state = PATH_START;
+ break;
+
+ case PATH_START:
+ path = c;
+ break;
+
+ default:
+ GIT_ASSERT("unhandled state");
+ }
+ }
+
+ if (!path)
+ return scp_invalid("path is required");
+
+ GIT_ERROR_CHECK_ALLOC(url->scheme = git__strdup("ssh"));
+
+ if (user_len)
+ GIT_ERROR_CHECK_ALLOC(url->username = git__strndup(user, user_len));
+
+ GIT_ASSERT(host_len);
+ GIT_ERROR_CHECK_ALLOC(url->host = git__strndup(host, host_len));
+
+ if (port_len)
+ GIT_ERROR_CHECK_ALLOC(url->port = git__strndup(port, port_len));
+ else
+ GIT_ERROR_CHECK_ALLOC(url->port = git__strdup(default_port));
+
+ GIT_ASSERT(path);
+ GIT_ERROR_CHECK_ALLOC(url->path = git__strdup(path));
+
+ return 0;
+}
+
int git_net_url_joinpath(
git_net_url *out,
git_net_url *one,
diff --git a/src/net.h b/src/net.h
index c743974..739769a 100644
--- a/src/net.h
+++ b/src/net.h
@@ -24,9 +24,12 @@ typedef struct git_net_url {
/** Duplicate a URL */
extern int git_net_url_dup(git_net_url *out, git_net_url *in);
-/** Parses a string containing a URL into a structure. */
+/** Parses a string containing a URL into a structure. */
extern int git_net_url_parse(git_net_url *url, const char *str);
+/** Parses a string containing an SCP style path into a URL structure. */
+extern int git_net_url_parse_scp(git_net_url *url, const char *str);
+
/** Appends a path and/or query string to the given URL */
extern int git_net_url_joinpath(
git_net_url *out,
diff --git a/src/transports/ssh.c b/src/transports/ssh.c
index f37bf70..0f4a0fc 100644
--- a/src/transports/ssh.c
+++ b/src/transports/ssh.c
@@ -258,37 +258,6 @@ static int ssh_stream_alloc(
return 0;
}
-static int git_ssh_extract_url_parts(
- git_net_url *urldata,
- const char *url)
-{
- char *colon, *at;
- const char *start;
-
- colon = strchr(url, ':');
-
-
- at = strchr(url, '@');
- if (at) {
- start = at + 1;
- urldata->username = git__substrdup(url, at - url);
- GIT_ERROR_CHECK_ALLOC(urldata->username);
- } else {
- start = url;
- urldata->username = NULL;
- }
-
- if (colon == NULL || (colon < start)) {
- git_error_set(GIT_ERROR_NET, "malformed URL");
- return -1;
- }
-
- urldata->host = git__substrdup(start, colon - start);
- GIT_ERROR_CHECK_ALLOC(urldata->host);
-
- return 0;
-}
-
static int ssh_agent_auth(LIBSSH2_SESSION *session, git_credential_ssh_key *c) {
int rc = LIBSSH2_ERROR_NONE;
@@ -546,14 +515,9 @@ static int _git_ssh_setup_conn(
goto post_extract;
}
}
- if ((error = git_ssh_extract_url_parts(&urldata, url)) < 0)
+ if ((error = git_net_url_parse_scp(&urldata, url)) < 0)
goto done;
- if (urldata.port == NULL)
- urldata.port = git__strdup(SSH_DEFAULT_PORT);
-
- GIT_ERROR_CHECK_ALLOC(urldata.port);
-
post_extract:
if ((error = git_socket_stream_new(&s->io, urldata.host, urldata.port)) < 0 ||
(error = git_stream_connect(s->io)) < 0)
diff --git a/tests/network/url/scp.c b/tests/network/url/scp.c
new file mode 100644
index 0000000..8cdc832
--- /dev/null
+++ b/tests/network/url/scp.c
@@ -0,0 +1,321 @@
+#include "clar_libgit2.h"
+#include "net.h"
+
+static git_net_url conndata;
+
+void test_network_url_scp__initialize(void)
+{
+ memset(&conndata, 0, sizeof(conndata));
+}
+
+void test_network_url_scp__cleanup(void)
+{
+ git_net_url_dispose(&conndata);
+}
+
+/* Hostname */
+
+void test_network_url_scp__hostname_trivial(void)
+{
+ cl_git_pass(git_net_url_parse_scp(&conndata, "example.com:/resource"));
+ cl_assert_equal_s(conndata.scheme, "ssh");
+ cl_assert_equal_s(conndata.host, "example.com");
+ cl_assert_equal_s(conndata.port, "22");
+ cl_assert_equal_s(conndata.path, "/resource");
+ cl_assert_equal_p(conndata.username, NULL);
+ cl_assert_equal_p(conndata.password, NULL);
+ cl_assert_equal_i(git_net_url_is_default_port(&conndata), 1);
+}
+
+void test_network_url_scp__hostname_bracketed(void)
+{
+ cl_git_pass(git_net_url_parse_scp(&conndata, "[example.com]:/resource"));
+ cl_assert_equal_s(conndata.scheme, "ssh");
+ cl_assert_equal_s(conndata.host, "example.com");
+ cl_assert_equal_s(conndata.port, "22");
+ cl_assert_equal_s(conndata.path, "/resource");
+ cl_assert_equal_p(conndata.username, NULL);
+ cl_assert_equal_p(conndata.password, NULL);
+ cl_assert_equal_i(git_net_url_is_default_port(&conndata), 1);
+}
+
+void test_network_url_scp__hostname_root(void)
+{
+ cl_git_pass(git_net_url_parse_scp(&conndata, "example.com:/"));
+ cl_assert_equal_s(conndata.scheme, "ssh");
+ cl_assert_equal_s(conndata.host, "example.com");
+ cl_assert_equal_s(conndata.port, "22");
+ cl_assert_equal_s(conndata.path, "/");
+ cl_assert_equal_p(conndata.username, NULL);
+ cl_assert_equal_p(conndata.password, NULL);
+ cl_assert_equal_i(git_net_url_is_default_port(&conndata), 1);
+}
+
+void test_network_url_scp__hostname_user(void)
+{
+ cl_git_pass(git_net_url_parse_scp(&conndata, "git@example.com:/resource"));
+ cl_assert_equal_s(conndata.scheme, "ssh");
+ cl_assert_equal_s(conndata.host, "example.com");
+ cl_assert_equal_s(conndata.port, "22");
+ cl_assert_equal_s(conndata.path, "/resource");
+ cl_assert_equal_s(conndata.username, "git");
+ cl_assert_equal_p(conndata.password, NULL);
+ cl_assert_equal_i(git_net_url_is_default_port(&conndata), 1);
+}
+
+void test_network_url_scp__hostname_user_bracketed(void)
+{
+ cl_git_pass(git_net_url_parse_scp(&conndata, "[git@example.com]:/resource"));
+ cl_assert_equal_s(conndata.scheme, "ssh");
+ cl_assert_equal_s(conndata.host, "example.com");
+ cl_assert_equal_s(conndata.port, "22");
+ cl_assert_equal_s(conndata.path, "/resource");
+ cl_assert_equal_s(conndata.username, "git");
+ cl_assert_equal_p(conndata.password, NULL);
+ cl_assert_equal_i(git_net_url_is_default_port(&conndata), 1);
+}
+
+void test_network_url_scp__hostname_port(void)
+{
+ cl_git_pass(git_net_url_parse_scp(&conndata, "[example.com:42]:/resource"));
+ cl_assert_equal_s(conndata.scheme, "ssh");
+ cl_assert_equal_s(conndata.host, "example.com");
+ cl_assert_equal_s(conndata.port, "42");
+ cl_assert_equal_s(conndata.path, "/resource");
+ cl_assert_equal_p(conndata.username, NULL);
+ cl_assert_equal_p(conndata.password, NULL);
+ cl_assert_equal_i(git_net_url_is_default_port(&conndata), 0);
+}
+
+void test_network_url_scp__hostname_user_port(void)
+{
+ cl_git_pass(git_net_url_parse_scp(&conndata, "[git@example.com:42]:/resource"));
+ cl_assert_equal_s(conndata.scheme, "ssh");
+ cl_assert_equal_s(conndata.host, "example.com");
+ cl_assert_equal_s(conndata.port, "42");
+ cl_assert_equal_s(conndata.path, "/resource");
+ cl_assert_equal_s(conndata.username, "git");
+ cl_assert_equal_p(conndata.password, NULL);
+ cl_assert_equal_i(git_net_url_is_default_port(&conndata), 0);
+}
+
+void test_network_url_scp__ipv4_trivial(void)
+{
+ cl_git_pass(git_net_url_parse_scp(&conndata, "192.168.99.88:/resource/a/b/c"));
+ cl_assert_equal_s(conndata.scheme, "ssh");
+ cl_assert_equal_s(conndata.host, "192.168.99.88");
+ cl_assert_equal_s(conndata.port, "22");
+ cl_assert_equal_s(conndata.path, "/resource/a/b/c");
+ cl_assert_equal_p(conndata.username, NULL);
+ cl_assert_equal_p(conndata.password, NULL);
+ cl_assert_equal_i(git_net_url_is_default_port(&conndata), 1);
+}
+
+void test_network_url_scp__ipv4_bracketed(void)
+{
+ cl_git_pass(git_net_url_parse_scp(&conndata, "[192.168.99.88]:/resource/a/b/c"));
+ cl_assert_equal_s(conndata.scheme, "ssh");
+ cl_assert_equal_s(conndata.host, "192.168.99.88");
+ cl_assert_equal_s(conndata.port, "22");
+ cl_assert_equal_s(conndata.path, "/resource/a/b/c");
+ cl_assert_equal_p(conndata.username, NULL);
+ cl_assert_equal_p(conndata.password, NULL);
+ cl_assert_equal_i(git_net_url_is_default_port(&conndata), 1);
+}
+
+void test_network_url_scp__ipv4_user(void)
+{
+ cl_git_pass(git_net_url_parse_scp(&conndata, "git@192.168.99.88:/resource/a/b/c"));
+ cl_assert_equal_s(conndata.scheme, "ssh");
+ cl_assert_equal_s(conndata.host, "192.168.99.88");
+ cl_assert_equal_s(conndata.port, "22");
+ cl_assert_equal_s(conndata.path, "/resource/a/b/c");
+ cl_assert_equal_s(conndata.username, "git");
+ cl_assert_equal_p(conndata.password, NULL);
+ cl_assert_equal_i(git_net_url_is_default_port(&conndata), 1);
+}
+
+void test_network_url_scp__ipv4_port(void)
+{
+ cl_git_pass(git_net_url_parse_scp(&conndata, "[192.168.99.88:1111]:/resource/a/b/c"));
+ cl_assert_equal_s(conndata.scheme, "ssh");
+ cl_assert_equal_s(conndata.host, "192.168.99.88");
+ cl_assert_equal_s(conndata.port, "1111");
+ cl_assert_equal_s(conndata.path, "/resource/a/b/c");
+ cl_assert_equal_p(conndata.username, NULL);
+ cl_assert_equal_p(conndata.password, NULL);
+ cl_assert_equal_i(git_net_url_is_default_port(&conndata), 0);
+}
+
+void test_network_url_scp__ipv4_user_port(void)
+{
+ cl_git_pass(git_net_url_parse_scp(&conndata, "[git@192.168.99.88:1111]:/resource/a/b/c"));
+ cl_assert_equal_s(conndata.scheme, "ssh");
+ cl_assert_equal_s(conndata.host, "192.168.99.88");
+ cl_assert_equal_s(conndata.port, "1111");
+ cl_assert_equal_s(conndata.path, "/resource/a/b/c");
+ cl_assert_equal_s(conndata.username, "git");
+ cl_assert_equal_p(conndata.password, NULL);
+ cl_assert_equal_i(git_net_url_is_default_port(&conndata), 0);
+}
+
+void test_network_url_scp__ipv6_trivial(void)
+{
+ cl_git_pass(git_net_url_parse_scp(&conndata, "[fe80::dcad:beff:fe00:0001]:/resource/foo"));
+ cl_assert_equal_s(conndata.scheme, "ssh");
+ cl_assert_equal_s(conndata.host, "[fe80::dcad:beff:fe00:0001]");
+ cl_assert_equal_s(conndata.port, "22");
+ cl_assert_equal_s(conndata.path, "/resource/foo");
+ cl_assert_equal_p(conndata.username, NULL);
+ cl_assert_equal_p(conndata.password, NULL);
+ cl_assert_equal_i(git_net_url_is_default_port(&conndata), 1);
+}
+
+void test_network_url_scp__ipv6_user(void)
+{
+ cl_git_pass(git_net_url_parse_scp(&conndata, "git@[fe80::dcad:beff:fe00:0001]:/resource/foo"));
+ cl_assert_equal_s(conndata.scheme, "ssh");
+ cl_assert_equal_s(conndata.host, "[fe80::dcad:beff:fe00:0001]");
+ cl_assert_equal_s(conndata.port, "22");
+ cl_assert_equal_s(conndata.path, "/resource/foo");
+ cl_assert_equal_s(conndata.username, "git");
+ cl_assert_equal_p(conndata.password, NULL);
+ cl_assert_equal_i(git_net_url_is_default_port(&conndata), 1);
+}
+
+void test_network_url_scp__ipv6_port(void)
+{
+ cl_git_pass(git_net_url_parse_scp(&conndata, "[[fe80::dcad:beff:fe00:0001]:99]:/resource/foo"));
+ cl_assert_equal_s(conndata.scheme, "ssh");
+ cl_assert_equal_s(conndata.host, "[fe80::dcad:beff:fe00:0001]");
+ cl_assert_equal_s(conndata.port, "99");
+ cl_assert_equal_s(conndata.path, "/resource/foo");
+ cl_assert_equal_p(conndata.username, NULL);
+ cl_assert_equal_p(conndata.password, NULL);
+ cl_assert_equal_i(git_net_url_is_default_port(&conndata), 0);
+}
+
+void test_network_url_scp__ipv6_user_port(void)
+{
+ cl_git_pass(git_net_url_parse_scp(&conndata, "[git@[fe80::dcad:beff:fe00:0001]:99]:/resource/foo"));
+ cl_assert_equal_s(conndata.scheme, "ssh");
+ cl_assert_equal_s(conndata.host, "[fe80::dcad:beff:fe00:0001]");
+ cl_assert_equal_s(conndata.port, "99");
+ cl_assert_equal_s(conndata.path, "/resource/foo");
+ cl_assert_equal_s(conndata.username, "git");
+ cl_assert_equal_p(conndata.password, NULL);
+ cl_assert_equal_i(git_net_url_is_default_port(&conndata), 0);
+}
+
+void test_network_url_scp__hexhost_and_port(void)
+{
+ cl_git_pass(git_net_url_parse_scp(&conndata, "[fe:22]:/resource/foo"));
+ cl_assert_equal_s(conndata.scheme, "ssh");
+ cl_assert_equal_s(conndata.host, "fe");
+ cl_assert_equal_s(conndata.port, "22");
+ cl_assert_equal_s(conndata.path, "/resource/foo");
+ cl_assert_equal_p(conndata.username, NULL);
+ cl_assert_equal_p(conndata.password, NULL);
+ cl_assert_equal_i(git_net_url_is_default_port(&conndata), 1);
+}
+
+void test_network_url_scp__malformed_ipv6_one(void)
+{
+ cl_git_pass(git_net_url_parse_scp(&conndata, "fe80::dcad:beff:fe00:0001]:/resource"));
+ cl_assert_equal_s(conndata.scheme, "ssh");
+ cl_assert_equal_s(conndata.host, "fe80");
+ cl_assert_equal_s(conndata.port, "22");
+ cl_assert_equal_s(conndata.path, ":dcad:beff:fe00:0001]:/resource");
+ cl_assert_equal_p(conndata.username, NULL);
+ cl_assert_equal_p(conndata.password, NULL);
+ cl_assert_equal_i(git_net_url_is_default_port(&conndata), 1);
+}
+
+void test_network_url_scp__malformed_ipv6_two(void)
+{
+ cl_git_pass(git_net_url_parse_scp(&conndata, "[fe80::dcad:beff:fe00:0001]:42]:/resource"));
+ cl_assert_equal_s(conndata.scheme, "ssh");
+ cl_assert_equal_s(conndata.host, "[fe80::dcad:beff:fe00:0001]");
+ cl_assert_equal_s(conndata.port, "22");
+ cl_assert_equal_s(conndata.path, "42]:/resource");
+ cl_assert_equal_p(conndata.username, NULL);
+ cl_assert_equal_p(conndata.password, NULL);
+ cl_assert_equal_i(git_net_url_is_default_port(&conndata), 1);
+}
+
+void test_network_url_scp__malformed_ipv6_with_user(void)
+{
+ cl_git_pass(git_net_url_parse_scp(&conndata, "git@[fe80::dcad:beff:fe00:0001]:42]:/resource"));
+ cl_assert_equal_s(conndata.scheme, "ssh");
+ cl_assert_equal_s(conndata.host, "[fe80::dcad:beff:fe00:0001]");
+ cl_assert_equal_s(conndata.port, "22");
+ cl_assert_equal_s(conndata.path, "42]:/resource");
+ cl_assert_equal_s(conndata.username, "git");
+ cl_assert_equal_p(conndata.password, NULL);
+ cl_assert_equal_i(git_net_url_is_default_port(&conndata), 1);
+}
+
+void test_network_url_scp__invalid_addresses(void)
+{
+ /* Path is required */
+ cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse_scp(&conndata,
+ "example.com"));
+ cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse_scp(&conndata,
+ "example.com:"));
+ cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse_scp(&conndata,
+ "[example.com:42]:"));
+ cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse_scp(&conndata,
+ "[git@example.com:42]:"));
+
+ /* Host is required */
+ cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse_scp(&conndata,
+ ":"));
+ cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse_scp(&conndata,
+ ":foo"));
+ cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse_scp(&conndata,
+ "git@:foo"));
+ cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse_scp(&conndata,
+ "[]:"));
+ cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse_scp(&conndata,
+ "git@[]:"));
+
+ /* User is required if specified */
+ cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse_scp(&conndata,
+ "@example.com:foo"));
+ cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse_scp(&conndata,
+ "@:foo"));
+ cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse_scp(&conndata,
+ "[@localhost:22]:foo"));
+
+ /* Port is required in brackets */
+ cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse_scp(&conndata,
+ "[example.com:]:foo"));
+ cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse_scp(&conndata,
+ "[git@example.com:]:foo"));
+ cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse_scp(&conndata,
+ "[fe:]:foo"));
+ cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse_scp(&conndata,
+ "[@localhost]:foo"));
+
+ /* Extra brackets are disallowed */
+ cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse_scp(&conndata,
+ "[git@[[fe80::dcad:beff:fe00:0001]]:42]:foo"));
+ cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse_scp(&conndata,
+ "[[git@[fe80::dcad:beff:fe00:0001]]:42]:foo"));
+ cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse_scp(&conndata,
+ "[[git@[fe80::dcad:beff:fe00:0001]:42]]:foo"));
+
+ /* Closing bracket missing */
+ cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse_scp(&conndata,
+ "[fe80::dcad:beff:fe00:0001:/resource"));
+ cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse_scp(&conndata,
+ "[[fe80::dcad:beff:fe00:0001]:42:/resource"));
+ cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse_scp(&conndata,
+ "[git@[fe80::dcad:beff:fe00:0001]:42:/resource"));
+ cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse_scp(&conndata,
+ "[git@[fe80::dcad:beff:fe00:0001:42]:/resource"));
+
+ /* Invalid character inside address */
+ cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse(&conndata,
+ "[fe8o::dcad:beff:fe00:0001]:/resource"));
+}