Created
February 17, 2023 15:54
-
-
Save reubenmiller/94f8abac5457f2b0bd88c7b5bf4bef91 to your computer and use it in GitHub Desktop.
Test cases to check tedge locking
This file contains hidden or 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
| #!/bin/sh | |
| cleanup() { | |
| sudo systemctl stop tedge-agent || true | |
| sudo rm -f /run/lock/tedge-agent.lock | |
| } | |
| test_case_1() { | |
| echo | |
| echo "--------------------------------------------------------" | |
| echo "Test case 1: sticky flag OFF, with chmod 666" | |
| echo "--------------------------------------------------------" | |
| cleanup | |
| chmod o-t /run/lock | |
| sudo -u tedge timeout 3 tedge-agent | |
| sudo chmod 666 /run/lock/tedge-agent.lock | |
| sudo timeout 3 tedge-agent | |
| } | |
| test_case_2() { | |
| echo | |
| echo "--------------------------------------------------------" | |
| echo "Test case 2: sticky flag OFF, without chmod 666" | |
| echo "--------------------------------------------------------" | |
| cleanup | |
| chmod o-t /run/lock | |
| sudo -u tedge timeout 3 tedge-agent | |
| sudo timeout 3 tedge-agent | |
| } | |
| # | |
| # Failing test cases | |
| # | |
| test_case_3() { | |
| echo | |
| echo "--------------------------------------------------------" | |
| echo "Test case 3: stick flag ON, chmod 666" | |
| echo "--------------------------------------------------------" | |
| cleanup | |
| chmod o+t /run/lock | |
| sudo -u tedge timeout 3 tedge-agent | |
| sudo chmod 666 /run/lock/tedge-agent.lock | |
| sudo timeout 3 tedge-agent | |
| } | |
| test_case_4() { | |
| echo | |
| echo "--------------------------------------------------------" | |
| echo "Test case 4: stick flag ON" | |
| echo "--------------------------------------------------------" | |
| cleanup | |
| # Will fail | |
| chmod o+t /run/lock | |
| sudo -u tedge timeout 3 tedge-agent | |
| sudo timeout 3 tedge-agent | |
| } | |
| test_case_5() { | |
| echo | |
| echo "--------------------------------------------------------" | |
| echo "Test case 5: stick flag ON, but try to turn off on single file" | |
| echo "--------------------------------------------------------" | |
| cleanup | |
| chmod o+t /run/lock | |
| chmod o-t /run/lock/tedge-agent.lock | |
| sudo -u tedge timeout 3 tedge-agent | |
| sudo timeout 3 tedge-agent | |
| } | |
| test_case_6() { | |
| echo | |
| echo "--------------------------------------------------------" | |
| echo "Test case 6: Use subfolder with sticky flag OFF" | |
| echo "--------------------------------------------------------" | |
| # cleanup | |
| sudo rm -rf /run/lock/tedge | |
| sudo chmod o+t /run/lock | |
| echo "Create subfolder with chmod 777 and without sticky" | |
| sudo mkdir -p /run/lock/tedge | |
| sudo chmod 777 /run/lock/tedge | |
| # Technically this is not needed, but used to ensure that the | |
| # subfolder definitely does not | |
| sudo chmod o-t /run/lock/tedge | |
| # Cleanup file | |
| sudo rm -f /run/lock/tedge/example.lock | |
| echo "tedge is creating a lock" | |
| sudo -u tedge sh -c "echo 'tedge' > /run/lock/tedge/example.lock" || echo "TEST FAILED" | |
| echo "root is overwriting the lock" | |
| sudo sh -c "echo 'pwned' > /run/lock/tedge/example.lock" || echo "TEST FAILED" | |
| } | |
| test_case_7() { | |
| echo | |
| echo "--------------------------------------------------------" | |
| echo "Test case 7: stick flag ON, chmod 666 - non root user" | |
| echo "--------------------------------------------------------" | |
| cleanup | |
| echo Should succeed | |
| sudo chmod o+t /run/lock | |
| sudo -u tedge timeout 3 tedge-agent | |
| sudo chmod 666 /run/lock/tedge-agent.lock | |
| sudo -u pi timeout 3 tedge-agent | |
| } | |
| test_case_8() { | |
| echo | |
| echo "--------------------------------------------------------" | |
| echo "Test case 8: stick flag ON - non root user" | |
| echo "--------------------------------------------------------" | |
| cleanup | |
| echo Should fail | |
| sudo chmod o+t /run/lock | |
| sudo -u tedge timeout 3 tedge-agent | |
| sudo -u pi timeout 3 tedge-agent | |
| } | |
| # --------- | |
| # main | |
| # --------- | |
| test_case_1 | |
| test_case_2 | |
| test_case_3 | |
| test_case_4 | |
| test_case_5 | |
| test_case_6 | |
| test_case_7 | |
| test_case_8 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The line to be changed is https://gist.github.com/reubenmiller/94f8abac5457f2b0bd88c7b5bf4bef91#file-lock-testcases-sh-L98