diff options
author | Treehugger Robot <treehugger-gerrit@google.com> | 2021-10-27 23:54:08 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2021-10-27 23:54:08 +0000 |
commit | 439d58769bd64bbad36279188539209f2d4c2b07 (patch) | |
tree | 6a4709841e622abaad951691e859a4ef59044903 /regress/unittests/misc/test_parse.c | |
parent | 393ead3e4a22c473a4d316e47f9bbda36f638188 (diff) | |
parent | aa1e1baec4e1cdc49d0ee7aec83d07e30adaf19f (diff) | |
download | openssh-abc54aa031ef2bbe527ed16c4012faa25d5d8d3c.tar.gz |
Merge "Merge commit 'bf944e3794eff5413f2df1ef37cddf96918c6bde' into HEAD"android-t-preview-2android-t-preview-1android-t-beta-3android-s-v2-beta-3android-s-qpr3-beta-1android-t-preview-1android-s-v2-beta-3android-s-qpr3-beta-1
Diffstat (limited to 'regress/unittests/misc/test_parse.c')
-rw-r--r-- | regress/unittests/misc/test_parse.c | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/regress/unittests/misc/test_parse.c b/regress/unittests/misc/test_parse.c new file mode 100644 index 000000000..727ff3dea --- /dev/null +++ b/regress/unittests/misc/test_parse.c @@ -0,0 +1,86 @@ +/* $OpenBSD: test_parse.c,v 1.1 2021/03/19 03:25:01 djm Exp $ */ +/* + * Regress test for misc user/host/URI parsing functions. + * + * Placed in the public domain. + */ + +#include "includes.h" + +#include <sys/types.h> +#include <sys/param.h> +#include <stdio.h> +#ifdef HAVE_STDINT_H +#include <stdint.h> +#endif +#include <stdlib.h> +#include <string.h> + +#include "../test_helper/test_helper.h" + +#include "log.h" +#include "misc.h" + +void test_parse(void); + +void +test_parse(void) +{ + int port; + char *user, *host, *path; + + TEST_START("misc_parse_user_host_path"); + ASSERT_INT_EQ(parse_user_host_path("someuser@some.host:some/path", + &user, &host, &path), 0); + ASSERT_STRING_EQ(user, "someuser"); + ASSERT_STRING_EQ(host, "some.host"); + ASSERT_STRING_EQ(path, "some/path"); + free(user); free(host); free(path); + TEST_DONE(); + + TEST_START("misc_parse_user_ipv4_path"); + ASSERT_INT_EQ(parse_user_host_path("someuser@1.22.33.144:some/path", + &user, &host, &path), 0); + ASSERT_STRING_EQ(user, "someuser"); + ASSERT_STRING_EQ(host, "1.22.33.144"); + ASSERT_STRING_EQ(path, "some/path"); + free(user); free(host); free(path); + TEST_DONE(); + + TEST_START("misc_parse_user_[ipv4]_path"); + ASSERT_INT_EQ(parse_user_host_path("someuser@[1.22.33.144]:some/path", + &user, &host, &path), 0); + ASSERT_STRING_EQ(user, "someuser"); + ASSERT_STRING_EQ(host, "1.22.33.144"); + ASSERT_STRING_EQ(path, "some/path"); + free(user); free(host); free(path); + TEST_DONE(); + + TEST_START("misc_parse_user_[ipv4]_nopath"); + ASSERT_INT_EQ(parse_user_host_path("someuser@[1.22.33.144]:", + &user, &host, &path), 0); + ASSERT_STRING_EQ(user, "someuser"); + ASSERT_STRING_EQ(host, "1.22.33.144"); + ASSERT_STRING_EQ(path, "."); + free(user); free(host); free(path); + TEST_DONE(); + + TEST_START("misc_parse_user_ipv6_path"); + ASSERT_INT_EQ(parse_user_host_path("someuser@[::1]:some/path", + &user, &host, &path), 0); + ASSERT_STRING_EQ(user, "someuser"); + ASSERT_STRING_EQ(host, "::1"); + ASSERT_STRING_EQ(path, "some/path"); + free(user); free(host); free(path); + TEST_DONE(); + + TEST_START("misc_parse_uri"); + ASSERT_INT_EQ(parse_uri("ssh", "ssh://someuser@some.host:22/some/path", + &user, &host, &port, &path), 0); + ASSERT_STRING_EQ(user, "someuser"); + ASSERT_STRING_EQ(host, "some.host"); + ASSERT_INT_EQ(port, 22); + ASSERT_STRING_EQ(path, "some/path"); + free(user); free(host); free(path); + TEST_DONE(); +} |