xref: /openssl/test/sysdefaulttest.c (revision 50153ad2)
1 /*
2  * Copyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved.
3  *
4  * Licensed under the Apache License 2.0 (the "License").  You may not use
5  * this file except in compliance with the License.  You can obtain a copy
6  * in the file LICENSE in the source distribution or at
7  * https://www.openssl.org/source/license.html
8  */
9 
10 #include <stdio.h>
11 #include <openssl/opensslconf.h>
12 
13 #include <string.h>
14 #include <openssl/evp.h>
15 #include <openssl/ssl.h>
16 #include <openssl/tls1.h>
17 #include "testutil.h"
18 
19 static int expect_failure = 0;
20 
test_func(void)21 static int test_func(void)
22 {
23     int ret = 0;
24     SSL_CTX *ctx;
25 
26     ctx = SSL_CTX_new(TLS_method());
27     if (expect_failure) {
28         if (!TEST_ptr_null(ctx))
29             goto err;
30     } else {
31         if (!TEST_ptr(ctx))
32             return 0;
33         if (!TEST_int_eq(SSL_CTX_get_min_proto_version(ctx), TLS1_2_VERSION)
34             && !TEST_int_eq(SSL_CTX_get_max_proto_version(ctx), TLS1_2_VERSION)) {
35             TEST_info("min/max version setting incorrect");
36             goto err;
37         }
38     }
39     ret = 1;
40  err:
41     SSL_CTX_free(ctx);
42     return ret;
43 }
44 
global_init(void)45 int global_init(void)
46 {
47     if (!OPENSSL_init_ssl(OPENSSL_INIT_ENGINE_ALL_BUILTIN
48                           | OPENSSL_INIT_LOAD_CONFIG, NULL))
49         return 0;
50     return 1;
51 }
52 
53 typedef enum OPTION_choice {
54     OPT_ERR = -1,
55     OPT_EOF = 0,
56     OPT_FAIL,
57     OPT_TEST_ENUM
58 } OPTION_CHOICE;
59 
test_get_options(void)60 const OPTIONS *test_get_options(void)
61 {
62     static const OPTIONS test_options[] = {
63         OPT_TEST_OPTIONS_DEFAULT_USAGE,
64         { "f", OPT_FAIL, '-', "A failure is expected" },
65         { NULL }
66     };
67     return test_options;
68 }
69 
setup_tests(void)70 int setup_tests(void)
71 {
72     OPTION_CHOICE o;
73 
74     while ((o = opt_next()) != OPT_EOF) {
75         switch (o) {
76         case OPT_FAIL:
77             expect_failure = 1;
78             break;
79         case OPT_TEST_CASES:
80             break;
81         default:
82             return 0;
83         }
84     }
85 
86     ADD_TEST(test_func);
87     return 1;
88 }
89