Browse Source

Add unit test for create_csr

pull/615/head
Tim Kimber 5 years ago
parent
commit
c90ca25ede
No known key found for this signature in database GPG Key ID: 3E1804964E76BD18
2 changed files with 56 additions and 0 deletions
  1. +2
    -0
      getssl
  2. +54
    -0
      test/u4-create-csr-and-ifs.bats

+ 2
- 0
getssl View File

@ -913,6 +913,8 @@ create_csr() { # create a csr using a given key (if it doesn't already exist)
if [[ "$(IFS=$'\n'; echo -n "${alldomains[*]}")" != "$domains_in_csr" ]]; then
info "existing csr at $csr_file does not have the same domains as the config - re-create-csr"
_RECREATE_CSR=1
else
test_output "Existing csr at $csr_file contains same domains as the config"
fi
fi
# end of ... check if domain csr exists - if not then create it


+ 54
- 0
test/u4-create-csr-and-ifs.bats View File

@ -0,0 +1,54 @@
#! /usr/bin/env bats
load '/bats-support/load.bash'
load '/bats-assert/load.bash'
load '/getssl/test/test_helper.bash'
# This is run for every test
setup() {
. /getssl/getssl --source
find_dns_utils
_RUNNING_TEST=1
_USE_DEBUG=0
}
@test "Check create_csr works for multiple domains" {
# Create a key
csr_key=$(mktemp -t getssl.XXXXXX.key) || error_exit "mktemp failed"
csr_file=$(mktemp -t getssl.XXXXXX.csr) || error_exit "mktemp failed"
SANS="a.getssl.test,b.getssl.test"
SANLIST="subjectAltName=DNS:${SANS//[, ]/,DNS:}"
create_key "$ACCOUNT_KEY_TYPE" "$csr_key" "$ACCOUNT_KEY_LENGTH"
# Create an initial csr
run create_csr $csr_file $csr_key
assert_success
# Check that calling create_csr with the same SANSLIST doesn't re-create the csr
run create_csr $csr_file $csr_key
assert_success
refute_line --partial "does not have the same domains"
# Check that calling create_csr with a different SANSLIST does re-create the csr
SANS="a.getssl.test,b.getssl.test,c.getssl.test"
SANLIST="subjectAltName=DNS:${SANS//[, ]/,DNS:}"
run create_csr $csr_file $csr_key
assert_success
assert_line --partial "does not contain"
# Check that calling create_csr with the same SANSLIST, but in a different order does not re-create the csr
SANS="c.getssl.test,a.getssl.test,b.getssl.test"
SANLIST="subjectAltName=DNS:${SANS//[, ]/,DNS:}"
run create_csr $csr_file $csr_key
assert_success
refute_line --partial "does not contain"
# Check that removing a domain from the SANSLIST causes the csr to be re-created
SANS="c.getssl.test,a.getssl.test"
SANLIST="subjectAltName=DNS:${SANS//[, ]/,DNS:}"
run create_csr $csr_file $csr_key
assert_success
assert_line --partial "does not have the same domains as the config"
}

Loading…
Cancel
Save