117680Spst/*
217680Spst * Copyright 2017-2020 The OpenSSL Project Authors. All Rights Reserved.
317680Spst * Copyright (c) 2017, Oracle and/or its affiliates.  All rights reserved.
417680Spst *
517680Spst * Licensed under the Apache License 2.0 (the "License").  You may not use
617680Spst * this file except in compliance with the License.  You can obtain a copy
717680Spst * in the file LICENSE in the source distribution or at
817680Spst * https://www.openssl.org/source/license.html
917680Spst */
1017680Spst
1117680Spst#include <stdio.h>
1217680Spst#include <openssl/err.h>
1317680Spst#include <openssl/x509_vfy.h>
1417680Spst
1517680Spst#include "testutil.h"
1617680Spst
1717680Spststatic int test_509_dup_cert(int n)
1817680Spst{
1917680Spst    int ret = 0;
2017680Spst    X509_STORE_CTX *sctx = NULL;
2175118Sfenner    X509_STORE *store = NULL;
2253146Sbrian    X509_LOOKUP *lookup = NULL;
2317680Spst    const char *cert_f = test_get_argument(n);
2417680Spst
2575118Sfenner    if (TEST_ptr(store = X509_STORE_new())
2675118Sfenner        && TEST_ptr(lookup = X509_STORE_add_lookup(store, X509_LOOKUP_file()))
2775118Sfenner        && TEST_true(X509_load_cert_file(lookup, cert_f, X509_FILETYPE_PEM))
2875118Sfenner        && TEST_true(X509_load_cert_file(lookup, cert_f, X509_FILETYPE_PEM)))
2975118Sfenner        ret = 1;
3075118Sfenner
3175118Sfenner    X509_STORE_CTX_free(sctx);
3275118Sfenner    X509_STORE_free(store);
3375118Sfenner    return ret;
3475118Sfenner}
3575118Sfenner
3617680SpstOPT_TEST_DECLARE_USAGE("cert.pem...\n")
3775118Sfenner
3875118Sfennerint setup_tests(void)
3975118Sfenner{
4075118Sfenner    size_t n;
4175118Sfenner
4275118Sfenner    if (!test_skip_common_options()) {
4375118Sfenner        TEST_error("Error parsing test options\n");
4475118Sfenner        return 0;
4575118Sfenner    }
4675118Sfenner
4775118Sfenner    n = test_get_argument_count();
4875118Sfenner    if (!TEST_int_gt(n, 0))
4917680Spst        return 0;
5017680Spst
5117680Spst    ADD_ALL_TESTS(test_509_dup_cert, n);
5217680Spst    return 1;
5317680Spst}
5417680Spst