Skip to content

Commit 001fecb

Browse files
authored
Merge pull request #129 from DrDaveD/subtests
add tests for "sub" value
2 parents b966c62 + 8bc725a commit 001fecb

File tree

4 files changed

+57
-0
lines changed

4 files changed

+57
-0
lines changed

tests/.regress-config.template

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
VAULTSERVER=
22
ISSUER=
3+
GROUPROLE=
4+
GROUPSUBPAT=
35
HASKERBEROS=true
46
#HASSSH=true
57
ROBOTKEYTAB=

tests/001-oidcauth/main

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11
htdestroytoken
2+
set -ex
23
htgettoken --nokerberos --nossh -a $VAULTSERVER -i $ISSUER
4+
if [ -n "$GROUPSUBPAT" ]; then
5+
# also check the sub from oidc flow (others in test 014)
6+
htdecodetoken | jq -r .sub | grep -v $GROUPSUBPAT
7+
fi

tests/014-checkdefaultsub/main

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
if [ -z "$GROUPSUBPAT" ]; then
2+
exit $SKIPCODE
3+
fi
4+
set -ex
5+
htgettoken --nokerberos --nooidc --nossh -a $VAULTSERVER -i $ISSUER --scopes="$TESTSCOPES"
6+
EXPTIME="$(htdecodetoken|jq -r .exp)"
7+
8+
# check sub for token exchange
9+
htgettoken --nossh -a $VAULTSERVER -i $ISSUER --scopes="$TESTSCOPES"
10+
htdecodetoken | jq -r .sub | grep -v $GROUPSUBPAT
11+
12+
# check sub for refresh
13+
# make sure that we don't request minsecs longer than the access token lifetime
14+
# by waiting a couple of seconds
15+
sleep 2
16+
NOW="$(date +%s)"
17+
let MINSECS=$EXPTIME-$NOW+1
18+
htgettoken --nooidc --nokerberos --nossh -a $VAULTSERVER -i $ISSUER --minsecs=$MINSECS
19+
EXPTIME2="$(htdecodetoken|jq -r .exp)"
20+
if [ "$EXPTIME" = "$EXPTIME2" ]; then
21+
echo "The access token was not renewed!"
22+
exit 1
23+
fi
24+
htdecodetoken | jq -r .sub | grep -v $GROUPSUBPAT

tests/015-checkgroupsub/main

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
if [ -z "$GROUPSUBPAT" ]; then
2+
exit $SKIPCODE
3+
fi
4+
set -ex
5+
# check sub for oidc flow with role
6+
htgettoken --nossh -a $VAULTSERVER -i $ISSUER -r $GROUPROLE
7+
htdecodetoken | jq -r .sub | grep $GROUPSUBPAT
8+
EXPTIME="$(htdecodetoken|jq -r .exp)"
9+
10+
# check sub for token exchange
11+
htgettoken --nossh -a $VAULTSERVER -i $ISSUER -r $GROUPROLE --scopes="$TESTSCOPES"
12+
htdecodetoken | jq -r .sub | grep $GROUPSUBPAT
13+
14+
# check sub for refresh
15+
# make sure that we don't request minsecs longer than the access token lifetime
16+
# by waiting a couple of seconds
17+
sleep 2
18+
NOW="$(date +%s)"
19+
let MINSECS=$EXPTIME-$NOW+1
20+
htgettoken --nooidc --nokerberos --nossh -a $VAULTSERVER -i $ISSUER -r $GROUPROLE --minsecs=$MINSECS
21+
EXPTIME2="$(htdecodetoken|jq -r .exp)"
22+
if [ "$EXPTIME" = "$EXPTIME2" ]; then
23+
echo "The access token was not renewed!"
24+
exit 1
25+
fi
26+
htdecodetoken | jq -r .sub | grep $GROUPSUBPAT

0 commit comments

Comments
 (0)