2017-10-28 15:31:37 +03:00
|
|
|
#include "config.h"
|
|
|
|
|
2011-02-12 17:06:15 +03:00
|
|
|
#define LIBSSH_STATIC
|
|
|
|
|
|
|
|
#include "torture.h"
|
|
|
|
|
2011-02-12 21:12:39 +03:00
|
|
|
#include "misc.c"
|
2011-02-13 13:55:31 +03:00
|
|
|
#include "error.c"
|
2011-02-12 17:06:15 +03:00
|
|
|
|
|
|
|
/*
|
2011-02-12 21:12:39 +03:00
|
|
|
* Test the behavior of ssh_is_ipaddr()
|
2011-02-12 17:06:15 +03:00
|
|
|
*/
|
2011-02-12 21:12:39 +03:00
|
|
|
static void torture_ssh_is_ipaddr(void **state) {
|
2011-02-12 17:06:15 +03:00
|
|
|
(void)state;
|
2011-02-12 21:14:30 +03:00
|
|
|
|
2011-02-12 21:12:39 +03:00
|
|
|
assert_int_equal(ssh_is_ipaddr("127.0.0.1"),1);
|
|
|
|
assert_int_equal(ssh_is_ipaddr("0.0.0.0"),1);
|
|
|
|
assert_int_equal(ssh_is_ipaddr("1.1.1.1"),1);
|
|
|
|
assert_int_equal(ssh_is_ipaddr("255.255.255.255"),1);
|
|
|
|
assert_int_equal(ssh_is_ipaddr("128.128.128.128"),1);
|
|
|
|
assert_int_equal(ssh_is_ipaddr("1.10.100.1"),1);
|
|
|
|
assert_int_equal(ssh_is_ipaddr("0.1.10.100"),1);
|
2011-02-12 17:06:15 +03:00
|
|
|
|
2011-02-12 21:14:30 +03:00
|
|
|
assert_int_equal(ssh_is_ipaddr("2001:0db8:85a3:0000:0000:8a2e:0370:7334"),1);
|
|
|
|
assert_int_equal(ssh_is_ipaddr("fe80:0000:0000:0000:0202:b3ff:fe1e:8329"),1);
|
|
|
|
assert_int_equal(ssh_is_ipaddr("fe80:0:0:0:202:b3ff:fe1e:8329"),1);
|
|
|
|
assert_int_equal(ssh_is_ipaddr("fe80::202:b3ff:fe1e:8329"),1);
|
2011-02-13 19:36:45 +03:00
|
|
|
assert_int_equal(ssh_is_ipaddr("::1"),1);
|
2011-02-12 21:14:30 +03:00
|
|
|
|
|
|
|
assert_int_equal(ssh_is_ipaddr("::ffff:192.0.2.128"),1);
|
|
|
|
|
2011-02-12 21:12:39 +03:00
|
|
|
assert_int_equal(ssh_is_ipaddr("0.0.0.0.0"),0);
|
|
|
|
assert_int_equal(ssh_is_ipaddr("0.0.0.0.a"),0);
|
|
|
|
assert_int_equal(ssh_is_ipaddr("a.0.0.0"),0);
|
|
|
|
assert_int_equal(ssh_is_ipaddr("0a.0.0.0.0"),0);
|
|
|
|
assert_int_equal(ssh_is_ipaddr(""),0);
|
|
|
|
assert_int_equal(ssh_is_ipaddr("0.0.0."),0);
|
2011-02-13 13:21:35 +03:00
|
|
|
assert_int_equal(ssh_is_ipaddr("0.0"),0);
|
|
|
|
assert_int_equal(ssh_is_ipaddr("0"),0);
|
2011-03-22 12:45:07 +03:00
|
|
|
assert_int_equal(ssh_is_ipaddr("255.255.255"),0);
|
2011-02-13 13:21:35 +03:00
|
|
|
|
|
|
|
assert_int_equal(ssh_is_ipaddr("2001:0db8:85a3:0000:0000:8a2e:0370:7334:1002"), 0);
|
|
|
|
assert_int_equal(ssh_is_ipaddr("fe80:x:202:b3ff:fe1e:8329"), 0);
|
2011-02-13 19:36:45 +03:00
|
|
|
assert_int_equal(ssh_is_ipaddr("fe80:x:202:b3ff:fe1e:8329"), 0);
|
|
|
|
assert_int_equal(ssh_is_ipaddr(":1"), 0);
|
2011-02-12 17:06:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int torture_run_tests(void) {
|
|
|
|
int rc;
|
2015-09-07 11:39:51 +03:00
|
|
|
struct CMUnitTest tests[] = {
|
|
|
|
cmocka_unit_test(torture_ssh_is_ipaddr)
|
2011-02-12 17:06:15 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
ssh_init();
|
2014-09-02 11:07:17 +04:00
|
|
|
torture_filter_tests(tests);
|
2015-09-07 11:39:51 +03:00
|
|
|
rc = cmocka_run_group_tests(tests, NULL, NULL);
|
2011-02-12 17:06:15 +03:00
|
|
|
ssh_finalize();
|
|
|
|
return rc;
|
|
|
|
}
|