-
Notifications
You must be signed in to change notification settings - Fork 587
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: add prompting tests for writes actioned by other pid
Signed-off-by: Oliver Calder <oliver.calder@canonical.com>
- Loading branch information
1 parent
78f98d9
commit 0c9af96
Showing
18 changed files
with
453 additions
and
14 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
...armor-prompting-integration-tests/create_multiple_actioned_by_other_pid_always_allow.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
{ | ||
"version": 1, | ||
"prompt-filter": { | ||
"snap": "prompting-client", | ||
"interface": "home", | ||
"constraints": { | ||
"path": "$BASE_PATH/.*" | ||
} | ||
}, | ||
"prompts": [ | ||
{ | ||
"prompt-filter": { | ||
"constraints": { | ||
"path": ".*/test1.txt", | ||
"requested-permissions": [ "write" ] | ||
} | ||
}, | ||
"reply": null | ||
}, | ||
{ | ||
"prompt-filter": { | ||
"constraints": { | ||
"path": ".*/test2.txt", | ||
"requested-permissions": [ "write" ] | ||
} | ||
}, | ||
"reply": null | ||
}, | ||
{ | ||
"prompt-filter": { | ||
"constraints": { | ||
"path": ".*/test3.txt", | ||
"requested-permissions": [ "write" ] | ||
} | ||
}, | ||
"reply": null | ||
}, | ||
{ | ||
"prompt-filter": { | ||
"constraints": { | ||
"path": ".*/test4.txt", | ||
"requested-permissions": [ "write" ] | ||
} | ||
}, | ||
"reply": { | ||
"action": "allow", | ||
"lifespan": "forever", | ||
"constraints": { | ||
"path-pattern": "${BASE_PATH}/test*.txt", | ||
"permissions": [ "write" ] | ||
} | ||
} | ||
} | ||
] | ||
} |
36 changes: 36 additions & 0 deletions
36
...pparmor-prompting-integration-tests/create_multiple_actioned_by_other_pid_always_allow.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/usr/bin/sh | ||
|
||
# A test that replying with allow forever actions previous matching prompts. | ||
|
||
TEST_DIR="$1" | ||
|
||
WRITABLE="$(snap run --shell prompting-client.scripted -c "cd ~; pwd")/$(basename "$TEST_DIR")" | ||
snap run --shell prompting-client.scripted -c "mkdir -p $WRITABLE" | ||
|
||
for name in test1.txt test2.txt test3.txt ; do | ||
echo "Attempt to write $name in the background" | ||
snap run --shell prompting-client.scripted -c "echo started > ${WRITABLE}/${name}; echo $name is written > ${TEST_DIR}/${name}" & | ||
timeout 10 sh -c "while ! [ -f '${WRITABLE}/${name}' ] ; do sleep 0.1 ; done" | ||
done | ||
|
||
echo "Attempt to write test4.txt (for which client will reply)" | ||
snap run --shell prompting-client.scripted -c "echo test4.txt is written > ${TEST_DIR}/test4.txt" | ||
|
||
# Wait for the client to write its result and exit | ||
timeout 5 sh -c 'while pgrep -f "prompting-client-scripted" > /dev/null; do sleep 0.1; done' | ||
|
||
CLIENT_OUTPUT="$(cat "${TEST_DIR}/result")" | ||
|
||
if [ "$CLIENT_OUTPUT" != "success" ] ; then | ||
echo "test failed" | ||
echo "output='$CLIENT_OUTPUT'" | ||
exit 1 | ||
fi | ||
|
||
for name in test1.txt test2.txt test3.txt test4.txt; do | ||
TEST_OUTPUT="$(cat "${TEST_DIR}/${name}")" | ||
if [ "$TEST_OUTPUT" != "$name is written" ] ; then | ||
echo "file creation failed for $name" | ||
exit 1 | ||
fi | ||
done |
55 changes: 55 additions & 0 deletions
55
...parmor-prompting-integration-tests/create_multiple_actioned_by_other_pid_always_deny.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
{ | ||
"version": 1, | ||
"prompt-filter": { | ||
"snap": "prompting-client", | ||
"interface": "home", | ||
"constraints": { | ||
"path": "$BASE_PATH/.*" | ||
} | ||
}, | ||
"prompts": [ | ||
{ | ||
"prompt-filter": { | ||
"constraints": { | ||
"path": ".*/test1.txt", | ||
"requested-permissions": [ "write" ] | ||
} | ||
}, | ||
"reply": null | ||
}, | ||
{ | ||
"prompt-filter": { | ||
"constraints": { | ||
"path": ".*/test2.txt", | ||
"requested-permissions": [ "write" ] | ||
} | ||
}, | ||
"reply": null | ||
}, | ||
{ | ||
"prompt-filter": { | ||
"constraints": { | ||
"path": ".*/test3.txt", | ||
"requested-permissions": [ "write" ] | ||
} | ||
}, | ||
"reply": null | ||
}, | ||
{ | ||
"prompt-filter": { | ||
"constraints": { | ||
"path": ".*/test4.txt", | ||
"requested-permissions": [ "write" ] | ||
} | ||
}, | ||
"reply": { | ||
"action": "deny", | ||
"lifespan": "forever", | ||
"constraints": { | ||
"path-pattern": "${BASE_PATH}/test*.txt", | ||
"permissions": [ "write" ] | ||
} | ||
} | ||
} | ||
] | ||
} |
35 changes: 35 additions & 0 deletions
35
...apparmor-prompting-integration-tests/create_multiple_actioned_by_other_pid_always_deny.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/usr/bin/sh | ||
|
||
# A test that replying with allow forever actions previous matching prompts. | ||
|
||
TEST_DIR="$1" | ||
|
||
WRITABLE="$(snap run --shell prompting-client.scripted -c "cd ~; pwd")/$(basename "$TEST_DIR")" | ||
snap run --shell prompting-client.scripted -c "mkdir -p $WRITABLE" | ||
|
||
for name in test1.txt test2.txt test3.txt ; do | ||
echo "Attempt to write $name in the background" | ||
snap run --shell prompting-client.scripted -c "echo started > ${WRITABLE}/${name}; echo $name is written > ${TEST_DIR}/${name}" & | ||
timeout 10 sh -c "while ! [ -f '${WRITABLE}/${name}' ] ; do sleep 0.1 ; done" | ||
done | ||
|
||
echo "Attempt to write test4.txt (for which client will reply)" | ||
snap run --shell prompting-client.scripted -c "echo test4.txt is written > ${TEST_DIR}/test4.txt" | ||
|
||
# Wait for the client to write its result and exit | ||
timeout 5 sh -c 'while pgrep -f "prompting-client-scripted" > /dev/null; do sleep 0.1; done' | ||
|
||
CLIENT_OUTPUT="$(cat "${TEST_DIR}/result")" | ||
|
||
if [ "$CLIENT_OUTPUT" != "success" ] ; then | ||
echo "test failed" | ||
echo "output='$CLIENT_OUTPUT'" | ||
exit 1 | ||
fi | ||
|
||
for name in test1.txt test2.txt test3.txt test4.txt; do | ||
if [ -f "${TEST_DIR}/${name}" ] ; then | ||
echo "file creation unexpectedly succeeded for $name" | ||
exit 1 | ||
fi | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
...r-prompting-integration-tests/create_multiple_not_actioned_by_other_pid_single_allow.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
{ | ||
"version": 1, | ||
"prompt-filter": { | ||
"snap": "prompting-client", | ||
"interface": "home", | ||
"constraints": { | ||
"path": "$BASE_PATH/.*" | ||
} | ||
}, | ||
"prompts": [ | ||
{ | ||
"prompt-filter": { | ||
"constraints": { | ||
"path": ".*/test1.txt", | ||
"requested-permissions": [ "write" ] | ||
} | ||
}, | ||
"reply": null | ||
}, | ||
{ | ||
"prompt-filter": { | ||
"constraints": { | ||
"path": ".*/test2.txt", | ||
"requested-permissions": [ "write" ] | ||
} | ||
}, | ||
"reply": null | ||
}, | ||
{ | ||
"prompt-filter": { | ||
"constraints": { | ||
"path": ".*/test3.txt", | ||
"requested-permissions": [ "write" ] | ||
} | ||
}, | ||
"reply": null | ||
}, | ||
{ | ||
"prompt-filter": { | ||
"constraints": { | ||
"path": ".*/test4.txt", | ||
"requested-permissions": [ "write" ] | ||
} | ||
}, | ||
"reply": { | ||
"action": "allow", | ||
"lifespan": "single", | ||
"constraints": { | ||
"path-pattern": "${BASE_PATH}/test*.txt", | ||
"permissions": [ "write" ] | ||
} | ||
} | ||
}, | ||
{ | ||
"prompt-filter": { | ||
"constraints": { | ||
"path": ".*/test4.txt", | ||
"requested-permissions": [ "write" ] | ||
} | ||
}, | ||
"reply": { | ||
"action": "allow", | ||
"lifespan": "single", | ||
"constraints": { | ||
"path-pattern": "${BASE_PATH}/test*.txt", | ||
"permissions": [ "write" ] | ||
} | ||
} | ||
}, | ||
{ | ||
"prompt-filter": { | ||
"constraints": { | ||
"path": ".*/test5.txt", | ||
"requested-permissions": [ "write" ] | ||
} | ||
}, | ||
"reply": { | ||
"action": "deny", | ||
"lifespan": "forever", | ||
"constraints": { | ||
"path-pattern": "${BASE_PATH}/test*.txt", | ||
"permissions": [ "write" ] | ||
} | ||
} | ||
} | ||
] | ||
} |
44 changes: 44 additions & 0 deletions
44
...mor-prompting-integration-tests/create_multiple_not_actioned_by_other_pid_single_allow.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#!/usr/bin/sh | ||
|
||
# A test that replying with allow forever actions previous matching prompts. | ||
|
||
TEST_DIR="$1" | ||
|
||
WRITABLE="$(snap run --shell prompting-client.scripted -c "cd ~; pwd")/$(basename "$TEST_DIR")" | ||
snap run --shell prompting-client.scripted -c "mkdir -p $WRITABLE" | ||
|
||
for name in test1.txt test2.txt test3.txt ; do | ||
echo "Attempt to write $name in the background" | ||
snap run --shell prompting-client.scripted -c "echo started > ${WRITABLE}/${name}; echo $name is written > ${TEST_DIR}/${name}" & | ||
timeout 10 sh -c "while ! [ -f '${WRITABLE}/${name}' ] ; do sleep 0.1 ; done" | ||
done | ||
|
||
echo "Attempt to write test4.txt (for which client will reply allow single)" | ||
snap run --shell prompting-client.scripted -c "echo test4.txt is written > ${TEST_DIR}/test4.txt" | ||
|
||
echo "Attempt to write test5.txt (for which client will reply deny forever)" | ||
snap run --shell prompting-client.scripted -c "echo test5.txt is written > ${TEST_DIR}/test5.txt" | ||
|
||
# Wait for the client to write its result and exit | ||
timeout 5 sh -c 'while pgrep -f "prompting-client-scripted" > /dev/null; do sleep 0.1; done' | ||
|
||
CLIENT_OUTPUT="$(cat "${TEST_DIR}/result")" | ||
|
||
if [ "$CLIENT_OUTPUT" != "success" ] ; then | ||
echo "test failed" | ||
echo "output='$CLIENT_OUTPUT'" | ||
exit 1 | ||
fi | ||
|
||
TEST_OUTPUT="$(cat "${TEST_DIR}/test4.txt")" | ||
if [ "$TEST_OUTPUT" != "test4.txt is written" ] ; then | ||
echo "file creation failed for test4.txt" | ||
exit 1 | ||
fi | ||
|
||
for name in test1.txt test2.txt test3.txt test5.txt; do | ||
if [ -f "${TEST_DIR}/${name}" ] ; then | ||
echo "file creation unexpectedly succeeded for $name" | ||
exit 1 | ||
fi | ||
done |
Oops, something went wrong.