Unit test for kex_proposal_populate_entries.
authordtucker <dtucker@openbsd.org>
Mon, 6 Mar 2023 12:15:47 +0000 (12:15 +0000)
committerdtucker <dtucker@openbsd.org>
Mon, 6 Mar 2023 12:15:47 +0000 (12:15 +0000)
regress/usr.bin/ssh/unittests/kex/test_proposal.c
regress/usr.bin/ssh/unittests/kex/tests.c

index b89ff59..c782304 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: test_proposal.c,v 1.1 2023/02/02 12:12:52 djm Exp $ */
+/*     $OpenBSD: test_proposal.c,v 1.2 2023/03/06 12:15:47 dtucker Exp $ */
 /*
  * Regress test KEX
  *
 
 #include "test_helper.h"
 
+#include "cipher.h"
 #include "compat.h"
 #include "ssherr.h"
 #include "sshbuf.h"
 #include "kex.h"
+#include "myproposal.h"
 #include "packet.h"
 #include "xmalloc.h"
 
-void kex_proposal(void);
+void kex_proposal_tests(void);
+void kex_proposal_populate_tests(void);
 
 #define CURVE25519 "curve25519-sha256@libssh.org"
 #define DHGEX1 "diffie-hellman-group-exchange-sha1"
 #define DHGEX256 "diffie-hellman-group-exchange-sha256"
 #define KEXALGOS CURVE25519","DHGEX256","DHGEX1
 void
-kex_proposal(void)
+kex_proposal_tests(void)
 {
        size_t i;
        struct ssh ssh;
@@ -77,3 +80,41 @@ kex_proposal(void)
        }
        TEST_DONE();
 }
+
+void
+kex_proposal_populate_tests(void)
+{
+       char *prop[PROPOSAL_MAX], *kexalgs, *ciphers, *macs, *hkalgs;
+       const char *comp = compression_alg_list(0);
+       int i;
+       struct ssh ssh;
+       struct kex kex;
+
+       kexalgs = kex_alg_list(',');
+       ciphers = cipher_alg_list(',', 0);
+       macs = mac_alg_list(',');
+       hkalgs = kex_alg_list(',');
+
+       ssh.kex = &kex;
+       TEST_START("compat_kex_proposal_populate");
+       for (i = 0; i <= 1; i++) {
+               kex.server = i;
+               for (ssh.compat = 0; ssh.compat < 0x40000000; ) {
+                       kex_proposal_populate_entries(&ssh, prop, NULL, NULL,
+                           NULL, NULL, NULL);
+                       kex_proposal_free_entries(prop);
+                       kex_proposal_populate_entries(&ssh, prop, kexalgs,
+                           ciphers, macs, hkalgs, comp);
+                       kex_proposal_free_entries(prop);
+                       if (ssh.compat == 0)
+                               ssh.compat = 1;
+                       else
+                               ssh.compat <<= 1;
+               }
+       }
+
+       free(kexalgs);
+       free(ciphers);
+       free(macs);
+       free(hkalgs);
+}
index 26592d5..7fa67fa 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: tests.c,v 1.2 2023/02/02 12:12:52 djm Exp $ */
+/*     $OpenBSD: tests.c,v 1.3 2023/03/06 12:15:47 dtucker Exp $ */
 /*
  * Placed in the public domain
  */
@@ -6,11 +6,13 @@
 #include "test_helper.h"
 
 void kex_tests(void);
-void kex_proposal(void);
+void kex_proposal_tests(void);
+void kex_proposal_populate_tests(void);
 
 void
 tests(void)
 {
        kex_tests();
-       kex_proposal();
+       kex_proposal_tests();
+       kex_proposal_populate_tests();
 }