Skip to content

Commit

Permalink
Fix the issue with add/remove.
Browse files Browse the repository at this point in the history
When the local trust sources are not present, add and remove fail to add
certificates.
  • Loading branch information
busykai committed Oct 5, 2017
1 parent f1bb549 commit b097805
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 1 deletion.
9 changes: 8 additions & 1 deletion clrtrust
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ find_all_certs() {
find_certs $CLR_LOCAL_TRUST_SRC/trusted
}

ensure_local_trust_src() {
mkdir -p ${CLR_LOCAL_TRUST_SRC}/trusted \
${CLR_LOCAL_TRUST_SRC}/distrusted \
&>/dev/null
}

print_generate_help() {
cat <<EOF
Usage: ${BASENAME} generate [-h|--help]
Expand Down Expand Up @@ -236,6 +242,7 @@ $1"
print_add_help
return $EINVAL
fi
ensure_local_trust_src
files=$(echo "$files" | sed -e '1d')
ca_certs=$(find_all_certs)
distrusted_certs=$(find_certs $CLR_LOCAL_TRUST_SRC/distrusted)
Expand Down Expand Up @@ -440,7 +447,7 @@ $1"
if [ $? -eq $EBADST ]; then
return $EBADST
fi

ensure_local_trust_src
err=$(mktemp)
out=$(mktemp)
files=$(echo "$files" | sed -e '1d')
Expand Down
28 changes: 28 additions & 0 deletions test/add-no-localsrc.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env bats
# Copyright 2017 Intel Corporation

load test_lib

setup() {
find_clrtrust
setup_fs
rm -rf $CLR_LOCAL_TRUST_SRC/trusted $CLR_LOCAL_TRUST_SRC/distrusted
}

@test "add cert when the local trust src is not there" {
# add acceptable CA
run $CLRTRUST add $CERTS/c1.pem
[ $status -eq 0 ]
run $CLRTRUST list
[ $status -eq 0 ]
cnt=$(echo "$output" | grep ^id | wc -l)
[ $cnt -eq 1 ]
[ -d $CLR_LOCAL_TRUST_SRC/trusted ]
[ -d $CLR_LOCAL_TRUST_SRC/distrusted ]
}

teardown() {
remove_fs
}

# vim: ft=sh:sw=4:ts=4:et:tw=80:si:noai:nocin
29 changes: 29 additions & 0 deletions test/distrust-no-localsrc.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env bats
# Copyright 2017 Intel Corporation

load test_lib

setup() {
find_clrtrust
setup_fs
cp $CERTS/c1.pem $CLR_CLEAR_TRUST_SRC/trusted
rm -rf $CLR_LOCAL_TRUST_SRC
}

@test "remove cert when local trust src is not there" {
# add acceptable CA
run $CLRTRUST remove $CERTS/c1.pem
[ $status -eq 0 ]
run $CLRTRUST list
[ $status -eq 0 ]
cnt=$(echo "$output" | grep ^id | wc -l)
[ $cnt -eq 0 ]
[ -d $CLR_LOCAL_TRUST_SRC/trusted ]
[ -d $CLR_LOCAL_TRUST_SRC/distrusted ]
}

teardown() {
remove_fs
}

# vim: ft=sh:sw=4:ts=4:et:tw=80:si:noai:nocin

0 comments on commit b097805

Please sign in to comment.