]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
tests/psk-file: fix heizenbug in last test 1090/head
authorDmitry Eremin-Solenikov <dbaryshkov@gmail.com>
Tue, 8 Oct 2019 21:10:09 +0000 (00:10 +0300)
committerDmitry Eremin-Solenikov <dbaryshkov@gmail.com>
Tue, 8 Oct 2019 21:10:09 +0000 (00:10 +0300)
Currently last test case in psk-file expects that the server will
terminate connection with fatal error and close connection. Client will
receive GNUTLS_E_PUSH_ERROR error. However on slow boxes (or under qemu)
client is able to receive server's fatal alert thus returning unexpected
error. To make this behaviour predictable make server wait for client to
read all data and actually close connection on it's own.

Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
tests/psk-file.c

index 0a6eef4b87e4ea9b8eac48e630dda07734a9d1e1..22e744f1a7793ab5f7478f029476814df0fa1942 100644 (file)
@@ -215,7 +215,16 @@ static void server(int sd, const char *prio, const char *user, bool no_cred,
        gnutls_transport_set_int(session, sd);
        ret = gnutls_handshake(session);
        if (ret < 0) {
+               unsigned char seq[8], buf[16];
                gnutls_alert_send_appropriate(session, ret);
+
+               /* We have to make sure that we do not close connection till
+                * test client reads our fatal alert, otherwise it migh exit
+                * with GNUTLS_E_PUSH_ERROR instead */
+               gnutls_session_force_valid(session);
+               while ((gnutls_record_recv_seq(session, buf, sizeof(buf), seq)) >= 0)
+                       ;
+
                if (expect_fail) {
                        if (ret != expect_fail) {
                                fail("expected error %d (%s), got %d (%s)\n", expect_fail,
@@ -410,7 +419,7 @@ void doit(void)
        run_test2("NORMAL:-VERS-ALL:+VERS-TLS1.3:+DHE-PSK:-GROUP-ALL:+GROUP-FFDHE2048:+GROUP-FFDHE4096", "NORMAL:-VERS-ALL:+VERS-TLS1.3:+DHE-PSK:-GROUP-ALL:+GROUP-FFDHE4096", "jas", &key, 0, GNUTLS_KX_DHE_PSK, 0, 0);
 
        /* try without server credentials */
-       run_test3("NORMAL:-VERS-ALL:+VERS-TLS1.3:+PSK:+DHE-PSK", NULL, "jas", &key, 1, 0, 0, GNUTLS_E_PUSH_ERROR, GNUTLS_E_INSUFFICIENT_CREDENTIALS);
+       run_test3("NORMAL:-VERS-ALL:+VERS-TLS1.3:+PSK:+DHE-PSK", NULL, "jas", &key, 1, 0, 0, GNUTLS_E_FATAL_ALERT_RECEIVED, GNUTLS_E_INSUFFICIENT_CREDENTIALS);
 }
 
 #endif                         /* _WIN32 */