diff options
Diffstat (limited to 'regress')
-rw-r--r-- | regress/unittests/hostkeys/test_iterate.c | 37 |
1 files changed, 34 insertions, 3 deletions
diff --git a/regress/unittests/hostkeys/test_iterate.c b/regress/unittests/hostkeys/test_iterate.c index 751825dda..d6963bd2a 100644 --- a/regress/unittests/hostkeys/test_iterate.c +++ b/regress/unittests/hostkeys/test_iterate.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: test_iterate.c,v 1.5 2017/04/30 23:33:48 djm Exp $ */ | 1 | /* $OpenBSD: test_iterate.c,v 1.6 2018/07/16 03:09:59 djm Exp $ */ |
2 | /* | 2 | /* |
3 | * Regress test for hostfile.h hostkeys_foreach() | 3 | * Regress test for hostfile.h hostkeys_foreach() |
4 | * | 4 | * |
@@ -152,6 +152,17 @@ prepare_expected(struct expected *expected, size_t n) | |||
152 | } | 152 | } |
153 | } | 153 | } |
154 | 154 | ||
155 | static void | ||
156 | cleanup_expected(struct expected *expected, size_t n) | ||
157 | { | ||
158 | size_t i; | ||
159 | |||
160 | for (i = 0; i < n; i++) { | ||
161 | sshkey_free(expected[i].l.key); | ||
162 | expected[i].l.key = NULL; | ||
163 | } | ||
164 | } | ||
165 | |||
155 | struct expected expected_full[] = { | 166 | struct expected expected_full[] = { |
156 | { NULL, -1, -1, 0, 0, 0, 0, -1, { | 167 | { NULL, -1, -1, 0, 0, 0, 0, -1, { |
157 | NULL, /* path, don't care */ | 168 | NULL, /* path, don't care */ |
@@ -825,6 +836,7 @@ test_iterate(void) | |||
825 | prepare_expected(expected_full, ctx.nexpected); | 836 | prepare_expected(expected_full, ctx.nexpected); |
826 | ASSERT_INT_EQ(hostkeys_foreach(test_data_file("known_hosts"), | 837 | ASSERT_INT_EQ(hostkeys_foreach(test_data_file("known_hosts"), |
827 | check, &ctx, NULL, NULL, ctx.flags), 0); | 838 | check, &ctx, NULL, NULL, ctx.flags), 0); |
839 | cleanup_expected(expected_full, ctx.nexpected); | ||
828 | TEST_DONE(); | 840 | TEST_DONE(); |
829 | 841 | ||
830 | TEST_START("hostkeys_iterate all without key parse"); | 842 | TEST_START("hostkeys_iterate all without key parse"); |
@@ -835,6 +847,7 @@ test_iterate(void) | |||
835 | prepare_expected(expected_full, ctx.nexpected); | 847 | prepare_expected(expected_full, ctx.nexpected); |
836 | ASSERT_INT_EQ(hostkeys_foreach(test_data_file("known_hosts"), | 848 | ASSERT_INT_EQ(hostkeys_foreach(test_data_file("known_hosts"), |
837 | check, &ctx, NULL, NULL, ctx.flags), 0); | 849 | check, &ctx, NULL, NULL, ctx.flags), 0); |
850 | cleanup_expected(expected_full, ctx.nexpected); | ||
838 | TEST_DONE(); | 851 | TEST_DONE(); |
839 | 852 | ||
840 | TEST_START("hostkeys_iterate specify host 1"); | 853 | TEST_START("hostkeys_iterate specify host 1"); |
@@ -846,6 +859,7 @@ test_iterate(void) | |||
846 | prepare_expected(expected_full, ctx.nexpected); | 859 | prepare_expected(expected_full, ctx.nexpected); |
847 | ASSERT_INT_EQ(hostkeys_foreach(test_data_file("known_hosts"), | 860 | ASSERT_INT_EQ(hostkeys_foreach(test_data_file("known_hosts"), |
848 | check, &ctx, "prometheus.example.com", NULL, ctx.flags), 0); | 861 | check, &ctx, "prometheus.example.com", NULL, ctx.flags), 0); |
862 | cleanup_expected(expected_full, ctx.nexpected); | ||
849 | TEST_DONE(); | 863 | TEST_DONE(); |
850 | 864 | ||
851 | TEST_START("hostkeys_iterate specify host 2"); | 865 | TEST_START("hostkeys_iterate specify host 2"); |
@@ -857,6 +871,7 @@ test_iterate(void) | |||
857 | prepare_expected(expected_full, ctx.nexpected); | 871 | prepare_expected(expected_full, ctx.nexpected); |
858 | ASSERT_INT_EQ(hostkeys_foreach(test_data_file("known_hosts"), | 872 | ASSERT_INT_EQ(hostkeys_foreach(test_data_file("known_hosts"), |
859 | check, &ctx, "sisyphus.example.com", NULL, ctx.flags), 0); | 873 | check, &ctx, "sisyphus.example.com", NULL, ctx.flags), 0); |
874 | cleanup_expected(expected_full, ctx.nexpected); | ||
860 | TEST_DONE(); | 875 | TEST_DONE(); |
861 | 876 | ||
862 | TEST_START("hostkeys_iterate match host 1"); | 877 | TEST_START("hostkeys_iterate match host 1"); |
@@ -868,6 +883,7 @@ test_iterate(void) | |||
868 | prepare_expected(expected_full, ctx.nexpected); | 883 | prepare_expected(expected_full, ctx.nexpected); |
869 | ASSERT_INT_EQ(hostkeys_foreach(test_data_file("known_hosts"), | 884 | ASSERT_INT_EQ(hostkeys_foreach(test_data_file("known_hosts"), |
870 | check, &ctx, "prometheus.example.com", NULL, ctx.flags), 0); | 885 | check, &ctx, "prometheus.example.com", NULL, ctx.flags), 0); |
886 | cleanup_expected(expected_full, ctx.nexpected); | ||
871 | TEST_DONE(); | 887 | TEST_DONE(); |
872 | 888 | ||
873 | TEST_START("hostkeys_iterate match host 2"); | 889 | TEST_START("hostkeys_iterate match host 2"); |
@@ -879,6 +895,7 @@ test_iterate(void) | |||
879 | prepare_expected(expected_full, ctx.nexpected); | 895 | prepare_expected(expected_full, ctx.nexpected); |
880 | ASSERT_INT_EQ(hostkeys_foreach(test_data_file("known_hosts"), | 896 | ASSERT_INT_EQ(hostkeys_foreach(test_data_file("known_hosts"), |
881 | check, &ctx, "sisyphus.example.com", NULL, ctx.flags), 0); | 897 | check, &ctx, "sisyphus.example.com", NULL, ctx.flags), 0); |
898 | cleanup_expected(expected_full, ctx.nexpected); | ||
882 | TEST_DONE(); | 899 | TEST_DONE(); |
883 | 900 | ||
884 | TEST_START("hostkeys_iterate specify host missing"); | 901 | TEST_START("hostkeys_iterate specify host missing"); |
@@ -889,6 +906,7 @@ test_iterate(void) | |||
889 | prepare_expected(expected_full, ctx.nexpected); | 906 | prepare_expected(expected_full, ctx.nexpected); |
890 | ASSERT_INT_EQ(hostkeys_foreach(test_data_file("known_hosts"), | 907 | ASSERT_INT_EQ(hostkeys_foreach(test_data_file("known_hosts"), |
891 | check, &ctx, "actaeon.example.org", NULL, ctx.flags), 0); | 908 | check, &ctx, "actaeon.example.org", NULL, ctx.flags), 0); |
909 | cleanup_expected(expected_full, ctx.nexpected); | ||
892 | TEST_DONE(); | 910 | TEST_DONE(); |
893 | 911 | ||
894 | TEST_START("hostkeys_iterate match host missing"); | 912 | TEST_START("hostkeys_iterate match host missing"); |
@@ -899,6 +917,7 @@ test_iterate(void) | |||
899 | prepare_expected(expected_full, ctx.nexpected); | 917 | prepare_expected(expected_full, ctx.nexpected); |
900 | ASSERT_INT_EQ(hostkeys_foreach(test_data_file("known_hosts"), | 918 | ASSERT_INT_EQ(hostkeys_foreach(test_data_file("known_hosts"), |
901 | check, &ctx, "actaeon.example.org", NULL, ctx.flags), 0); | 919 | check, &ctx, "actaeon.example.org", NULL, ctx.flags), 0); |
920 | cleanup_expected(expected_full, ctx.nexpected); | ||
902 | TEST_DONE(); | 921 | TEST_DONE(); |
903 | 922 | ||
904 | TEST_START("hostkeys_iterate specify IPv4"); | 923 | TEST_START("hostkeys_iterate specify IPv4"); |
@@ -910,6 +929,7 @@ test_iterate(void) | |||
910 | prepare_expected(expected_full, ctx.nexpected); | 929 | prepare_expected(expected_full, ctx.nexpected); |
911 | ASSERT_INT_EQ(hostkeys_foreach(test_data_file("known_hosts"), | 930 | ASSERT_INT_EQ(hostkeys_foreach(test_data_file("known_hosts"), |
912 | check, &ctx, "tiresias.example.org", "192.0.2.1", ctx.flags), 0); | 931 | check, &ctx, "tiresias.example.org", "192.0.2.1", ctx.flags), 0); |
932 | cleanup_expected(expected_full, ctx.nexpected); | ||
913 | TEST_DONE(); | 933 | TEST_DONE(); |
914 | 934 | ||
915 | TEST_START("hostkeys_iterate specify IPv6"); | 935 | TEST_START("hostkeys_iterate specify IPv6"); |
@@ -921,6 +941,7 @@ test_iterate(void) | |||
921 | prepare_expected(expected_full, ctx.nexpected); | 941 | prepare_expected(expected_full, ctx.nexpected); |
922 | ASSERT_INT_EQ(hostkeys_foreach(test_data_file("known_hosts"), | 942 | ASSERT_INT_EQ(hostkeys_foreach(test_data_file("known_hosts"), |
923 | check, &ctx, "tiresias.example.org", "2001:db8::1", ctx.flags), 0); | 943 | check, &ctx, "tiresias.example.org", "2001:db8::1", ctx.flags), 0); |
944 | cleanup_expected(expected_full, ctx.nexpected); | ||
924 | TEST_DONE(); | 945 | TEST_DONE(); |
925 | 946 | ||
926 | TEST_START("hostkeys_iterate match IPv4"); | 947 | TEST_START("hostkeys_iterate match IPv4"); |
@@ -932,6 +953,7 @@ test_iterate(void) | |||
932 | prepare_expected(expected_full, ctx.nexpected); | 953 | prepare_expected(expected_full, ctx.nexpected); |
933 | ASSERT_INT_EQ(hostkeys_foreach(test_data_file("known_hosts"), | 954 | ASSERT_INT_EQ(hostkeys_foreach(test_data_file("known_hosts"), |
934 | check, &ctx, "tiresias.example.org", "192.0.2.1", ctx.flags), 0); | 955 | check, &ctx, "tiresias.example.org", "192.0.2.1", ctx.flags), 0); |
956 | cleanup_expected(expected_full, ctx.nexpected); | ||
935 | TEST_DONE(); | 957 | TEST_DONE(); |
936 | 958 | ||
937 | TEST_START("hostkeys_iterate match IPv6"); | 959 | TEST_START("hostkeys_iterate match IPv6"); |
@@ -943,6 +965,7 @@ test_iterate(void) | |||
943 | prepare_expected(expected_full, ctx.nexpected); | 965 | prepare_expected(expected_full, ctx.nexpected); |
944 | ASSERT_INT_EQ(hostkeys_foreach(test_data_file("known_hosts"), | 966 | ASSERT_INT_EQ(hostkeys_foreach(test_data_file("known_hosts"), |
945 | check, &ctx, "tiresias.example.org", "2001:db8::1", ctx.flags), 0); | 967 | check, &ctx, "tiresias.example.org", "2001:db8::1", ctx.flags), 0); |
968 | cleanup_expected(expected_full, ctx.nexpected); | ||
946 | TEST_DONE(); | 969 | TEST_DONE(); |
947 | 970 | ||
948 | TEST_START("hostkeys_iterate specify addr missing"); | 971 | TEST_START("hostkeys_iterate specify addr missing"); |
@@ -953,6 +976,7 @@ test_iterate(void) | |||
953 | prepare_expected(expected_full, ctx.nexpected); | 976 | prepare_expected(expected_full, ctx.nexpected); |
954 | ASSERT_INT_EQ(hostkeys_foreach(test_data_file("known_hosts"), | 977 | ASSERT_INT_EQ(hostkeys_foreach(test_data_file("known_hosts"), |
955 | check, &ctx, "tiresias.example.org", "192.168.0.1", ctx.flags), 0); | 978 | check, &ctx, "tiresias.example.org", "192.168.0.1", ctx.flags), 0); |
979 | cleanup_expected(expected_full, ctx.nexpected); | ||
956 | TEST_DONE(); | 980 | TEST_DONE(); |
957 | 981 | ||
958 | TEST_START("hostkeys_iterate match addr missing"); | 982 | TEST_START("hostkeys_iterate match addr missing"); |
@@ -963,6 +987,7 @@ test_iterate(void) | |||
963 | prepare_expected(expected_full, ctx.nexpected); | 987 | prepare_expected(expected_full, ctx.nexpected); |
964 | ASSERT_INT_EQ(hostkeys_foreach(test_data_file("known_hosts"), | 988 | ASSERT_INT_EQ(hostkeys_foreach(test_data_file("known_hosts"), |
965 | check, &ctx, "tiresias.example.org", "::1", ctx.flags), 0); | 989 | check, &ctx, "tiresias.example.org", "::1", ctx.flags), 0); |
990 | cleanup_expected(expected_full, ctx.nexpected); | ||
966 | TEST_DONE(); | 991 | TEST_DONE(); |
967 | 992 | ||
968 | TEST_START("hostkeys_iterate specify host 2 and IPv4"); | 993 | TEST_START("hostkeys_iterate specify host 2 and IPv4"); |
@@ -975,6 +1000,7 @@ test_iterate(void) | |||
975 | prepare_expected(expected_full, ctx.nexpected); | 1000 | prepare_expected(expected_full, ctx.nexpected); |
976 | ASSERT_INT_EQ(hostkeys_foreach(test_data_file("known_hosts"), | 1001 | ASSERT_INT_EQ(hostkeys_foreach(test_data_file("known_hosts"), |
977 | check, &ctx, "sisyphus.example.com", "192.0.2.1", ctx.flags), 0); | 1002 | check, &ctx, "sisyphus.example.com", "192.0.2.1", ctx.flags), 0); |
1003 | cleanup_expected(expected_full, ctx.nexpected); | ||
978 | TEST_DONE(); | 1004 | TEST_DONE(); |
979 | 1005 | ||
980 | TEST_START("hostkeys_iterate match host 1 and IPv6"); | 1006 | TEST_START("hostkeys_iterate match host 1 and IPv6"); |
@@ -986,7 +1012,9 @@ test_iterate(void) | |||
986 | ctx.match_ipv6 = 1; | 1012 | ctx.match_ipv6 = 1; |
987 | prepare_expected(expected_full, ctx.nexpected); | 1013 | prepare_expected(expected_full, ctx.nexpected); |
988 | ASSERT_INT_EQ(hostkeys_foreach(test_data_file("known_hosts"), | 1014 | ASSERT_INT_EQ(hostkeys_foreach(test_data_file("known_hosts"), |
989 | check, &ctx, "prometheus.example.com", "2001:db8::1", ctx.flags), 0); | 1015 | check, &ctx, "prometheus.example.com", |
1016 | "2001:db8::1", ctx.flags), 0); | ||
1017 | cleanup_expected(expected_full, ctx.nexpected); | ||
990 | TEST_DONE(); | 1018 | TEST_DONE(); |
991 | 1019 | ||
992 | TEST_START("hostkeys_iterate specify host 2 and IPv4 w/ key parse"); | 1020 | TEST_START("hostkeys_iterate specify host 2 and IPv4 w/ key parse"); |
@@ -999,6 +1027,7 @@ test_iterate(void) | |||
999 | prepare_expected(expected_full, ctx.nexpected); | 1027 | prepare_expected(expected_full, ctx.nexpected); |
1000 | ASSERT_INT_EQ(hostkeys_foreach(test_data_file("known_hosts"), | 1028 | ASSERT_INT_EQ(hostkeys_foreach(test_data_file("known_hosts"), |
1001 | check, &ctx, "sisyphus.example.com", "192.0.2.1", ctx.flags), 0); | 1029 | check, &ctx, "sisyphus.example.com", "192.0.2.1", ctx.flags), 0); |
1030 | cleanup_expected(expected_full, ctx.nexpected); | ||
1002 | TEST_DONE(); | 1031 | TEST_DONE(); |
1003 | 1032 | ||
1004 | TEST_START("hostkeys_iterate match host 1 and IPv6 w/ key parse"); | 1033 | TEST_START("hostkeys_iterate match host 1 and IPv6 w/ key parse"); |
@@ -1010,7 +1039,9 @@ test_iterate(void) | |||
1010 | ctx.match_ipv6 = 1; | 1039 | ctx.match_ipv6 = 1; |
1011 | prepare_expected(expected_full, ctx.nexpected); | 1040 | prepare_expected(expected_full, ctx.nexpected); |
1012 | ASSERT_INT_EQ(hostkeys_foreach(test_data_file("known_hosts"), | 1041 | ASSERT_INT_EQ(hostkeys_foreach(test_data_file("known_hosts"), |
1013 | check, &ctx, "prometheus.example.com", "2001:db8::1", ctx.flags), 0); | 1042 | check, &ctx, "prometheus.example.com", |
1043 | "2001:db8::1", ctx.flags), 0); | ||
1044 | cleanup_expected(expected_full, ctx.nexpected); | ||
1014 | TEST_DONE(); | 1045 | TEST_DONE(); |
1015 | } | 1046 | } |
1016 | 1047 | ||