Statistics
| Branch: | Tag: | Revision:

root / test / check-cert-expired_unittest.bash @ 1a2eb2dc

History | View | Annotate | Download (1.9 kB)

1
#!/bin/bash
2
#
3

    
4
# Copyright (C) 2010 Google Inc.
5
#
6
# This program is free software; you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation; either version 2 of the License, or
9
# (at your option) any later version.
10
#
11
# This program is distributed in the hope that it will be useful, but
12
# WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
# General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License
17
# along with this program; if not, write to the Free Software
18
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19
# 02110-1301, USA.
20

    
21
set -e
22
set -o pipefail
23

    
24
export PYTHON=${PYTHON:=python}
25

    
26
CCE=tools/check-cert-expired
27

    
28
err() {
29
  echo "$@"
30
  echo 'Aborting'
31
  exit 1
32
}
33

    
34
impexpd_helper() {
35
  $PYTHON "${TOP_SRCDIR:-.}/test/import-export_unittest-helper" "$@"
36
}
37

    
38
$CCE 2>/dev/null && err 'Accepted empty argument list'
39
$CCE foo bar 2>/dev/null && err 'Accepted more than one argument'
40
$CCE foo bar baz 2>/dev/null && err 'Accepted more than one argument'
41

    
42
tmpdir=$(mktemp -d)
43
trap "rm -rf $tmpdir" EXIT
44

    
45
[[ -f "$tmpdir/cert-not" ]] && err 'File existed when it should not'
46
$CCE $tmpdir/cert-not 2>/dev/null && err 'Accepted non-existent file'
47

    
48
VALIDITY=1 impexpd_helper $tmpdir/cert-valid gencert
49
$CCE $tmpdir/cert-valid 2>/dev/null && \
50
  err 'Reported valid certificate as expired'
51

    
52
VALIDITY=-50 impexpd_helper $tmpdir/cert-expired gencert
53
$CCE $tmpdir/cert-expired 2>/dev/null || \
54
  err 'Reported expired certificate as valid'
55

    
56
echo > $tmpdir/cert-invalid
57
$CCE $tmpdir/cert-invalid 2>/dev/null && \
58
  err 'Reported invalid certificate as expired'
59

    
60
echo 'Hello World' > $tmpdir/cert-invalid2
61
$CCE $tmpdir/cert-invalid2 2>/dev/null && \
62
  err 'Reported invalid certificate as expired'
63

    
64
exit 0