Skip to content

Commit f96f7cd

Browse files
committed
tests: add prompting spread test for special character paths
Signed-off-by: Oliver Calder <oliver.calder@canonical.com>
1 parent b54d7dd commit f96f7cd

3 files changed

Lines changed: 100 additions & 9 deletions

File tree

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"version": 1,
3+
"prompt-filter": {
4+
"snap": "prompting-client",
5+
"interface": "home",
6+
"constraints": {
7+
"path": "$BASE_PATH/.*"
8+
}
9+
},
10+
"prompts": [
11+
{
12+
"prompt-filter": {
13+
"constraints": {
14+
"path": "${BASE_PATH}/\\\\\\[アニメ\\\\\\]\\\\\\[ゲーム動画\\\\\\].mkv",
15+
"requested-permissions": [ "read" ]
16+
}
17+
},
18+
"reply": {
19+
"action": "allow",
20+
"lifespan": "single",
21+
"constraints": {
22+
"path-pattern": "${BASE_PATH}/\\[アニメ\\]\\[ゲーム動画\\].mkv",
23+
"permissions": [ "read" ]
24+
}
25+
}
26+
},
27+
{
28+
"prompt-filter": {
29+
"constraints": {
30+
"path": "${BASE_PATH}/foo\\\\*\\\\?()\\\\[\\\\]\\\\{\\\\}\\\\\\\\",
31+
"requested-permissions": [ "read" ]
32+
}
33+
},
34+
"reply": {
35+
"action": "allow",
36+
"lifespan": "single",
37+
"constraints": {
38+
"path-pattern": "${BASE_PATH}/foo\\*\\?()\\[\\]\\{\\}\\\\",
39+
"permissions": [ "read" ]
40+
}
41+
}
42+
}
43+
]
44+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/sh
2+
3+
# Test prompting for filepaths which contain special characters.
4+
5+
TEST_DIR="$1"
6+
TIMEOUT="$2"
7+
if [ -z "$TIMEOUT" ] ; then
8+
TIMEOUT=10
9+
fi
10+
11+
FIRST_CONTENT="a file with square brackets and unicode"
12+
SECOND_CONTENT="a file with all the special characters"
13+
14+
# Prompt sequence prompt-filters are regular expressions, and they're stored as
15+
# json, so we annoyingly have to escape special characters twice in just the
16+
# prompt-filter path, with extra complexity for literal '\' characters.
17+
echo "Prepare the files to be read"
18+
echo "$FIRST_CONTENT" | tee "${TEST_DIR}/[アニメ][ゲーム動画].mkv"
19+
echo "$SECOND_CONTENT" | tee "${TEST_DIR}/foo*?()[]{}\\"
20+
21+
echo "Attempt to read the first file"
22+
FIRST_OUTPUT="$(snap run --shell prompting-client.scripted -c "cat ${TEST_DIR}/'[アニメ][ゲーム動画].mkv'")"
23+
24+
echo "Attempt to read the second file"
25+
SECOND_OUTPUT="$(snap run --shell prompting-client.scripted -c "cat ${TEST_DIR}/'foo*?()[]{}\\'")"
26+
27+
# Wait for the client to write its result and exit
28+
timeout "$TIMEOUT" sh -c "while pgrep -f 'prompting-client.scripted.*${TEST_DIR}' > /dev/null; do sleep 0.1; done"
29+
30+
CLIENT_OUTPUT="$(cat "${TEST_DIR}/result")"
31+
32+
if [ "$CLIENT_OUTPUT" != "success" ] ; then
33+
echo "test failed"
34+
echo "output='$CLIENT_OUTPUT'"
35+
exit 1
36+
fi
37+
38+
if [ "$FIRST_OUTPUT" != "$FIRST_CONTENT" ] ; then
39+
echo "test script failed"
40+
exit 1
41+
fi
42+
43+
if [ "$SECOND_OUTPUT" != "$SECOND_CONTENT" ] ; then
44+
echo "test script failed"
45+
exit 1
46+
fi

tests/main/apparmor-prompting-integration-tests/task.yaml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,24 @@ systems:
1414
- ubuntu-2*
1515

1616
environment:
17-
VARIANT/read_single_allow: read_single_allow
18-
VARIANT/read_single_deny: read_single_deny
19-
VARIANT/write_single_allow: write_single_allow
20-
VARIANT/write_single_deny: write_single_deny
17+
VARIANT/create_multiple_actioned_by_other_pid_always_allow: create_multiple_actioned_by_other_pid_always_allow
18+
VARIANT/create_multiple_actioned_by_other_pid_always_deny: create_multiple_actioned_by_other_pid_always_deny
2119
VARIANT/create_multiple_allow: create_multiple_allow
2220
VARIANT/create_multiple_deny: create_multiple_deny
21+
VARIANT/create_multiple_not_actioned_by_other_pid_single_allow: create_multiple_not_actioned_by_other_pid_single_allow
22+
VARIANT/create_multiple_not_actioned_by_other_pid_single_deny: create_multiple_not_actioned_by_other_pid_single_deny
23+
VARIANT/download_file_conflict: download_file_conflict
2324
VARIANT/download_file_defaults: download_file_defaults
2425
VARIANT/download_file_safer: download_file_safer
25-
VARIANT/download_file_conflict: download_file_conflict
26+
VARIANT/read_single_allow: read_single_allow
27+
VARIANT/read_single_deny: read_single_deny
28+
VARIANT/special_characters: special_characters
2629
VARIANT/timespan_allow: timespan_allow
2730
VARIANT/timespan_deny: timespan_deny
28-
VARIANT/create_multiple_actioned_by_other_pid_always_allow: create_multiple_actioned_by_other_pid_always_allow
29-
VARIANT/create_multiple_actioned_by_other_pid_always_deny: create_multiple_actioned_by_other_pid_always_deny
30-
VARIANT/create_multiple_not_actioned_by_other_pid_single_allow: create_multiple_not_actioned_by_other_pid_single_allow
31-
VARIANT/create_multiple_not_actioned_by_other_pid_single_deny: create_multiple_not_actioned_by_other_pid_single_deny
3231
VARIANT/write_read_multiple_actioned_by_other_pid_allow_deny: write_read_multiple_actioned_by_other_pid_allow_deny
3332
VARIANT/write_read_multiple_actioned_by_other_pid_deny_allow: write_read_multiple_actioned_by_other_pid_deny_allow
33+
VARIANT/write_single_allow: write_single_allow
34+
VARIANT/write_single_deny: write_single_deny
3435

3536
TIMEOUT: "30" # Define common timeout which can be modified as needed
3637

0 commit comments

Comments
 (0)