summaryrefslogtreecommitdiff
path: root/keyutils-1.5.6/tests/keyctl/unlink/all/runtest.sh
blob: 2014470d32e403df52823e9c00604b4bf746f13e (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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/bin/sh

. ../../../prepare.inc.sh
. ../../../toolbox.inc.sh


# ---- do the actual testing ----

result=PASS

if keyutils_at_or_later_than 1.5
then
    echo "++++ BEGINNING TEST" >$OUTPUTFILE

    # create a keyring and attach it to the session keyring
    marker "ADD KEYRING"
    create_keyring wibble @s
    expect_keyid keyringid

    # stick a key in the keyring
    marker "ADD KEY"
    create_key user lizard gizzard $keyringid
    expect_keyid keyid

    # check that we can list it
    marker "LIST KEYRING WITH ONE"
    list_keyring $keyringid
    expect_keyring_rlist rlist $keyid

    # dispose of the key and make sure it gets destroyed
    marker "UNLINK KEY FROM KEYRING"
    unlink_key --wait $keyid $keyringid

    # trying a tree-wide unlink should succeed with no links removed
    marker "CHECK NO UNLINK KEY FROM TREE"
    unlink_key $keyid
    expect_unlink_count n_unlinked 0

    # check that the keyring is now empty 
    marker "LIST KEYRING"
    list_keyring $keyringid
    expect_keyring_rlist rlist empty

    # create a key to be massively linked
    marker "ADD MULTI KEY"
    create_key user lizard gizzard $keyringid
    expect_keyid keyid

    # stick twenty keyrings in the keyring with twenty links
    marker "ADD TWENTY KEYRINGS WITH LINKS"
    subrings=
    for ((i=0; i<20; i++))
    do
	create_keyring ring$i $keyringid
	expect_keyid x
	keys="$keys $x"
	subrings="$subrings $x"
	list_keyring $keyringid
	expect_keyring_rlist rlist $x

	link_key $keyid $x
	list_keyring $x
	expect_keyring_rlist rlist $keyid
    done

    marker "SHOW"
    if ! keyctl show >>$OUTPUTFILE 2>&1
    then
        failed
    fi

    # delete all the keys from the keyring tree
    marker "REMOVE ALL LINKS TO KEY"
    unlink_key $keyid
    expect_unlink_count n_unlinked 21

    # there should not now be any left
    unlink_key $keyid
    expect_unlink_count n_unlinked 0

    # check that the key is no longer in the main keyring
    marker "CHECK GONE"
    list_keyring $keyringid
    expect_keyring_rlist rlist $keyid --absent

    for i in $subrings
    do
	list_keyring $i
	expect_keyring_rlist rlist $keyid --absent
    done

    # remove the keyring we added
    marker "UNLINK KEY"
    unlink_key $keyringid @s

    echo "++++ FINISHED TEST: $result" >>$OUTPUTFILE
else
    echo "++++ SKIPPING TEST" >>$OUTPUTFILE
    marker SKIP on version
fi

# --- then report the results in the database ---
toolbox_report_result $TEST $result