-
Notifications
You must be signed in to change notification settings - Fork 680
tests: add audio-record prompting integration tests #17015
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
182cbb2
a44b90a
995dd16
e0eb992
b84b14c
d875236
9d51f3d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| { | ||
| "version": 1, | ||
| "prompt-filter": { | ||
| "snap": "prompt-requester", | ||
| "interface": "audio-record" | ||
| }, | ||
| "prompts": [ | ||
| { | ||
| "prompt-filter": { | ||
| "interface": "audio-record", | ||
| "constraints": { | ||
| "requested-permissions": [ "access" ] | ||
| } | ||
| }, | ||
| "reply": { | ||
| "action": "allow", | ||
| "lifespan": "single", | ||
| "constraints": { | ||
| "permissions": [ "access" ] | ||
| } | ||
| } | ||
| }, | ||
| { | ||
| "prompt-filter": { | ||
| "interface": "audio-record", | ||
| "constraints": { | ||
| "requested-permissions": [ "access" ] | ||
| } | ||
| }, | ||
| "reply": { | ||
| "action": "deny", | ||
| "lifespan": "single", | ||
| "constraints": { | ||
| "permissions": [ "access" ] | ||
| } | ||
| } | ||
| }, | ||
| { | ||
| "prompt-filter": { | ||
| "interface": "audio-record", | ||
| "constraints": { | ||
| "requested-permissions": [ "access" ] | ||
| } | ||
| }, | ||
| "reply": { | ||
| "action": "deny", | ||
| "lifespan": "single", | ||
| "constraints": { | ||
| "permissions": [ "access" ] | ||
| } | ||
| } | ||
| }, | ||
| { | ||
| "prompt-filter": { | ||
| "interface": "audio-record", | ||
| "constraints": { | ||
| "requested-permissions": [ "access" ] | ||
| } | ||
| }, | ||
| "reply": { | ||
| "action": "allow", | ||
| "lifespan": "single", | ||
| "constraints": { | ||
| "permissions": [ "access" ] | ||
| } | ||
| } | ||
| }, | ||
| { | ||
| "prompt-filter": { | ||
| "interface": "audio-record", | ||
| "constraints": { | ||
| "requested-permissions": [ "access" ] | ||
| } | ||
| }, | ||
| "reply": { | ||
| "action": "allow", | ||
| "lifespan": "single", | ||
| "constraints": { | ||
| "permissions": [ "access" ] | ||
| } | ||
| } | ||
| } | ||
| ] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| #!/usr/bin/sh | ||
|
|
||
| # A test of allow once for the audio-record interface. | ||
|
|
||
| TEST_DIR="$1" | ||
| TIMEOUT="$2" | ||
| if [ -z "$TIMEOUT" ] ; then | ||
| TIMEOUT=10 | ||
| fi | ||
|
|
||
| SNAP_HOME="$HOME/snap/prompt-requester/current" | ||
| rm -f "$SNAP_HOME/running.pid" # Clean up any PID file from previous run | ||
|
|
||
| # The audio-record interface doesn't use a target file to trigger a prompt. | ||
| # Instead, we use a file to tell the snap to finish running. We need a snap | ||
| # running under a cgroup in order for the "ask" request to be handled correctly. | ||
| TARGET_FILE="$SNAP_HOME/finish" | ||
| rm -f "$TARGET_FILE" | ||
|
|
||
| # Start the snap running in the background so "ask" can use its PID to look up | ||
| # its cgroup, and from that derive the snap name. | ||
| prompt-requester.wait-for "$TARGET_FILE" & | ||
| WAITER_SHELL_PID="$!" | ||
|
|
||
|
Comment on lines
+20
to
+24
|
||
| # Background PID will be of the /snap/bin command, not the internal script, so | ||
| # need to get the real PID. The snap will write its own PID to | ||
| # $SNAP_HOME/running.pid | ||
| for i in $(seq 10) ; do | ||
| if [ -f "$SNAP_HOME/running.pid" ] ; then | ||
| break | ||
| fi | ||
| sleep 1 | ||
| done | ||
| test -f "$SNAP_HOME/running.pid" | ||
| WAITER_SNAP_PID="$(cat "$SNAP_HOME/running.pid")" | ||
|
|
||
|
olivercalder marked this conversation as resolved.
|
||
| # Actually trigger the request by querying the API | ||
| ASK_BODY="{\"action\": \"ask\", \"interface\": \"audio-record\", \"pid\": $WAITER_SNAP_PID}" | ||
| RESULT="$(echo "$ASK_BODY" | snap debug api -X POST -H 'Content-Type: application/json' "/v2/interfaces/requests")" | ||
| echo "$RESULT" | grep '"status-code": 200' | ||
| echo "$RESULT" | grep '"outcome": "allow"' | ||
|
|
||
| # Trigger a second request | ||
| ASK_BODY="{\"action\": \"ask\", \"interface\": \"audio-record\", \"pid\": $WAITER_SNAP_PID}" | ||
| RESULT="$(echo "$ASK_BODY" | snap debug api -X POST -H 'Content-Type: application/json' "/v2/interfaces/requests")" | ||
| echo "$RESULT" | grep '"status-code": 200' | ||
| echo "$RESULT" | grep '"outcome": "deny"' | ||
|
|
||
| # Trigger a third request | ||
| ASK_BODY="{\"action\": \"ask\", \"interface\": \"audio-record\", \"pid\": $WAITER_SNAP_PID}" | ||
| RESULT="$(echo "$ASK_BODY" | snap debug api -X POST -H 'Content-Type: application/json' "/v2/interfaces/requests")" | ||
| echo "$RESULT" | grep '"status-code": 200' | ||
| echo "$RESULT" | grep '"outcome": "deny"' | ||
|
|
||
| # Trigger a fourth request | ||
| ASK_BODY="{\"action\": \"ask\", \"interface\": \"audio-record\", \"pid\": $WAITER_SNAP_PID}" | ||
| RESULT="$(echo "$ASK_BODY" | snap debug api -X POST -H 'Content-Type: application/json' "/v2/interfaces/requests")" | ||
| echo "$RESULT" | grep '"status-code": 200' | ||
| echo "$RESULT" | grep '"outcome": "allow"' | ||
|
|
||
| # Trigger a fifth request | ||
| ASK_BODY="{\"action\": \"ask\", \"interface\": \"audio-record\", \"pid\": $WAITER_SNAP_PID}" | ||
| RESULT="$(echo "$ASK_BODY" | snap debug api -X POST -H 'Content-Type: application/json' "/v2/interfaces/requests")" | ||
| echo "$RESULT" | grep '"status-code": 200' | ||
| echo "$RESULT" | grep '"outcome": "allow"' | ||
|
|
||
| # Tell the waiter to stop waiting | ||
| touch "$TARGET_FILE" | ||
| wait "$WAITER_SHELL_PID" | ||
|
|
||
| # Wait for the client to write its result and exit | ||
| for i in $(seq "$TIMEOUT") ; do | ||
| if ! pgrep -af "prompting-client.scripted.*${TEST_DIR}" ; then | ||
| break | ||
| fi | ||
| sleep 1 | ||
| done | ||
| if pgrep -af "prompting-client.scripted.*${TEST_DIR}" ; then | ||
| echo "prompting-client.scripted still running" | ||
| exit 1 | ||
| fi | ||
|
|
||
| CLIENT_OUTPUT="$(cat "${TEST_DIR}/result")" | ||
|
|
||
| if [ "$CLIENT_OUTPUT" != "success" ] ; then | ||
| echo "test failed" | ||
| echo "output='$CLIENT_OUTPUT'" | ||
| exit 1 | ||
| fi | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| { | ||
| "version": 1, | ||
| "prompt-filter": { | ||
| "snap": "prompt-requester", | ||
| "interface": "audio-record" | ||
| }, | ||
| "prompts": [ | ||
| { | ||
| "prompt-filter": { | ||
| "interface": "audio-record", | ||
| "constraints": { | ||
| "requested-permissions": [ "access" ] | ||
| } | ||
| }, | ||
| "reply": { | ||
| "action": "allow", | ||
| "lifespan": "timespan", | ||
| "duration": "10s", | ||
| "constraints": { | ||
|
olivercalder marked this conversation as resolved.
|
||
| "permissions": [ "access" ] | ||
| } | ||
| } | ||
| }, | ||
| { | ||
| "prompt-filter": { | ||
| "interface": "audio-record", | ||
| "constraints": { | ||
| "requested-permissions": [ "access" ] | ||
| } | ||
| }, | ||
| "reply": { | ||
| "action": "deny", | ||
| "lifespan": "single", | ||
| "constraints": { | ||
| "permissions": [ "access" ] | ||
| } | ||
| } | ||
| } | ||
| ] | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| #!/usr/bin/sh | ||
|
|
||
| # A test of allow with timespan for the audio-record interface. | ||
|
|
||
| TEST_DIR="$1" | ||
| TIMEOUT="$2" | ||
| if [ -z "$TIMEOUT" ] ; then | ||
| TIMEOUT=10 | ||
| fi | ||
|
|
||
| SNAP_HOME="$HOME/snap/prompt-requester/current" | ||
| rm -f "$SNAP_HOME/running.pid" # Clean up any PID file from previous run | ||
|
|
||
| # The audio-record interface doesn't use a target file to trigger a prompt. | ||
| # Instead, we use a file to tell the snap to finish running. We need a snap | ||
| # running under a cgroup in order for the "ask" request to be handled correctly. | ||
| TARGET_FILE="$SNAP_HOME/finish" | ||
| rm -f "$TARGET_FILE" | ||
|
|
||
| # Start the snap running in the background so "ask" can use its PID to look up | ||
| # its cgroup, and from that derive the snap name. | ||
| prompt-requester.wait-for "$TARGET_FILE" & | ||
| WAITER_SHELL_PID="$!" | ||
|
olivercalder marked this conversation as resolved.
|
||
|
|
||
|
Comment on lines
+20
to
+24
|
||
| # Background PID will be of the /snap/bin command, not the internal script, so | ||
| # need to get the real PID. The snap will write its own PID to | ||
| # $SNAP_HOME/running.pid | ||
| for i in $(seq 10) ; do | ||
| if [ -f "$SNAP_HOME/running.pid" ] ; then | ||
| break | ||
| fi | ||
| sleep 1 | ||
| done | ||
| test -f "$SNAP_HOME/running.pid" | ||
| WAITER_SNAP_PID="$(cat "$SNAP_HOME/running.pid")" | ||
|
|
||
|
olivercalder marked this conversation as resolved.
|
||
| # Actually trigger the request by querying the API | ||
| ASK_BODY="{\"action\": \"ask\", \"interface\": \"audio-record\", \"pid\": $WAITER_SNAP_PID}" | ||
| RESULT="$(echo "$ASK_BODY" | snap debug api -X POST -H 'Content-Type: application/json' "/v2/interfaces/requests")" | ||
| echo "$RESULT" | grep '"status-code": 200' | ||
| echo "$RESULT" | grep '"outcome": "allow"' | ||
|
|
||
| # Trigger a second request | ||
| ASK_BODY="{\"action\": \"ask\", \"interface\": \"audio-record\", \"pid\": $WAITER_SNAP_PID}" | ||
| RESULT="$(echo "$ASK_BODY" | snap debug api -X POST -H 'Content-Type: application/json' "/v2/interfaces/requests")" | ||
| echo "$RESULT" | grep '"status-code": 200' | ||
| echo "$RESULT" | grep '"outcome": "allow"' | ||
|
|
||
| # Trigger a third request | ||
| ASK_BODY="{\"action\": \"ask\", \"interface\": \"audio-record\", \"pid\": $WAITER_SNAP_PID}" | ||
| RESULT="$(echo "$ASK_BODY" | snap debug api -X POST -H 'Content-Type: application/json' "/v2/interfaces/requests")" | ||
| echo "$RESULT" | grep '"status-code": 200' | ||
| echo "$RESULT" | grep '"outcome": "allow"' | ||
|
|
||
| # Trigger a fourth request | ||
| ASK_BODY="{\"action\": \"ask\", \"interface\": \"audio-record\", \"pid\": $WAITER_SNAP_PID}" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a concern that this fourth request is triggered close to the 10second duration of the initial response?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think so, these requests should be basically instantaneous. |
||
| RESULT="$(echo "$ASK_BODY" | snap debug api -X POST -H 'Content-Type: application/json' "/v2/interfaces/requests")" | ||
| echo "$RESULT" | grep '"status-code": 200' | ||
| echo "$RESULT" | grep '"outcome": "allow"' | ||
|
|
||
| echo "Wait for the rule to expire" | ||
| sleep 10 | ||
|
|
||
| # Trigger a fifth request | ||
| ASK_BODY="{\"action\": \"ask\", \"interface\": \"audio-record\", \"pid\": $WAITER_SNAP_PID}" | ||
| RESULT="$(echo "$ASK_BODY" | snap debug api -X POST -H 'Content-Type: application/json' "/v2/interfaces/requests")" | ||
| echo "$RESULT" | grep '"status-code": 200' | ||
| echo "$RESULT" | grep '"outcome": "deny"' | ||
|
|
||
| # Tell the waiter to stop waiting | ||
| touch "$TARGET_FILE" | ||
| wait "$WAITER_SHELL_PID" | ||
|
|
||
| # Wait for the client to write its result and exit | ||
| for i in $(seq "$TIMEOUT") ; do | ||
| if ! pgrep -af "prompting-client.scripted.*${TEST_DIR}" ; then | ||
| break | ||
| fi | ||
| sleep 1 | ||
| done | ||
| if pgrep -af "prompting-client.scripted.*${TEST_DIR}" ; then | ||
| echo "prompting-client.scripted still running" | ||
| exit 1 | ||
| fi | ||
|
|
||
| CLIENT_OUTPUT="$(cat "${TEST_DIR}/result")" | ||
|
|
||
| if [ "$CLIENT_OUTPUT" != "success" ] ; then | ||
| echo "test failed" | ||
| echo "output='$CLIENT_OUTPUT'" | ||
| exit 1 | ||
| fi | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| { | ||
| "version": 1, | ||
| "prompt-filter": { | ||
| "snap": "prompt-requester", | ||
| "interface": "audio-record" | ||
| }, | ||
| "prompts": [ | ||
| { | ||
| "prompt-filter": { | ||
| "interface": "audio-record", | ||
| "constraints": { | ||
| "requested-permissions": [ "access" ] | ||
| } | ||
| }, | ||
| "reply": { | ||
| "action": "deny", | ||
| "lifespan": "timespan", | ||
| "duration": "10s", | ||
| "constraints": { | ||
| "permissions": [ "access" ] | ||
| } | ||
| } | ||
| }, | ||
| { | ||
| "prompt-filter": { | ||
| "interface": "audio-record", | ||
| "constraints": { | ||
| "requested-permissions": [ "access" ] | ||
| } | ||
| }, | ||
| "reply": { | ||
| "action": "allow", | ||
| "lifespan": "single", | ||
| "constraints": { | ||
| "permissions": [ "access" ] | ||
| } | ||
| } | ||
| } | ||
| ] | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.