summaryrefslogtreecommitdiff
path: root/tests/policy/policy.sh
blob: f3d16eb64beda2a37e749a9b399cb9ee20c74c4d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#! /bin/bash
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

########################################################################
#
# mozilla/security/nss/tests/policy/policy.sh
#
# Script to test NSS crypto policy code
#
########################################################################

policy_init()
{
  SCRIPTNAME=policy.sh      # sourced - $0 would point to all.sh

  if [ -z "${CLEANUP}" ] ; then     # if nobody else is responsible for
      CLEANUP="${SCRIPTNAME}"       # cleaning this script will do it
  fi

  if [ -z "${INIT_SOURCED}" -o "${INIT_SOURCED}" != "TRUE" ]; then
      cd ../common
      . ./init.sh
  fi
  SCRIPTNAME=policy.sh

}

policy_cleanup()
{
  cd ${QADIR}
  . common/cleanup.sh
}

ignore_blank_lines()
{
  LC_ALL=C egrep -v '^[[:space:]]*(#|$)' "$1"
}

policy_run_tests()
{
  html_head "CRYPTO-POLICY"

  POLICY_INPUT=${QADIR}/policy/crypto-policy.txt

  ignore_blank_lines ${POLICY_INPUT} | \
  while read value policy match testname
  do
    echo "$SCRIPTNAME: running \"$testname\" ----------------------------"
    policy=`echo ${policy} | sed -e 's;_; ;g'`
    match=`echo ${match} | sed -e 's;_; ;g'`
    POLICY_FILE="${TMP}/nss-policy"

    echo "$SCRIPTNAME: policy: \"$policy\""

    cat > "$POLICY_FILE" << ++EOF++
library=
name=Policy
NSS=flags=policyOnly,moduleDB
++EOF++
    echo "config=\"${policy}\"" >> "$POLICY_FILE"
    echo "" >> "$POLICY_FILE"

    nss-policy-check "$POLICY_FILE" >${TMP}/$HOST.tmp.$$ 2>&1
    ret=$?
    cat ${TMP}/$HOST.tmp.$$

    html_msg $ret $value "\"${testname}\"" \
        "produced a returncode of $ret, expected is $value"

    egrep "${match}" ${TMP}/$HOST.tmp.$$
    ret=$?
    html_msg $ret 0 "\"${testname}\" output is expected to match \"${match}\""

  done
  html "</TABLE><BR>"
}

policy_init
policy_run_tests
policy_cleanup