Skip to content

Commit

Permalink
Validate result code of commands
Browse files Browse the repository at this point in the history
Signed-off-by: Vitor Mattos <[email protected]>
  • Loading branch information
vitormattos committed Mar 20, 2024
1 parent b34003a commit 666d611
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 44 deletions.
8 changes: 4 additions & 4 deletions tests/integration/features/account/create_to_sign.feature
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Feature: account/create_to_sign
Background:
Given as user "admin"
And run the command "libresign:configure:openssl --cn test"
And run the command "libresign:configure:openssl --cn test" with result code 0
And sending "post" to ocs "/apps/provisioning_api/api/v1/config/apps/libresign/identify_methods"
| value | (string)[{"name":"email","enabled":true,"mandatory":true,"can_create_account":true}] |
And my inbox is empty
Expand All @@ -14,8 +14,8 @@ Feature: account/create_to_sign

Scenario: Try to create with invalid data
Given as user ""
And run the command "user:delete [email protected]"
And run the command "user:delete signer1"
And run the command "user:delete [email protected]" with result code 0
And run the command "user:delete signer1" with result code 0
And I open the latest email to "[email protected]" with subject "LibreSign: There is a file for you to sign"
And I fetch the signer UUID from opened email
And follow the link on opened email
Expand All @@ -36,7 +36,7 @@ Feature: account/create_to_sign

Scenario: Create with valid data
Given as user ""
And run the command "user:delete [email protected]"
And run the command "user:delete [email protected]" with result code 0
And I open the latest email to "[email protected]" with subject "LibreSign: There is a file for you to sign"
And I fetch the signer UUID from opened email
And follow the link on opened email
Expand Down
18 changes: 9 additions & 9 deletions tests/integration/features/account/signature.feature
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ Feature: account/signature

Scenario: Create root certificate with CFSSL engine using API
Given as user "admin"
And run the command "config:app:set libresign certificate_engine --value cfssl"
And run the command "libresign:install --cfssl"
And run the command "config:app:set libresign certificate_engine --value cfssl" with result code 0
And run the command "libresign:install --cfssl" with result code 0
And sending "post" to ocs "/apps/libresign/api/v1/admin/certificate/cfssl"
| rootCert | {"commonName":"Common Name","names":{"C":{"id":"C","value":"BR"},"ST":{"id":"ST","value":"State of Company"},"L":{"id":"L","value":"City name"},"O":{"id":"O","value":"Organization"},"OU":{"id":"OU","value":"Organizational Unit"}}} |
And the response should have a status code 200
Expand All @@ -31,9 +31,9 @@ Feature: account/signature
Given user "signer1" exists
And set the email of user "signer1" to "[email protected]"
And as user "signer1"
And run the command "config:app:set libresign certificate_engine --value cfssl"
And run the command "libresign:install --cfssl"
And run the command "libresign:configure:cfssl --cn=Common\ Name --c=BR --o=Organization --st=State\ of\ Company --l=City\ Name"
And run the command "config:app:set libresign certificate_engine --value cfssl" with result code 0
And run the command "libresign:install --cfssl" with result code 0
And run the command "libresign:configure:cfssl --cn=Common\ Name --c=BR --o=Organization --st=State\ of\ Company --l=City\ Name" with result code 0
And sending "post" to ocs "/apps/libresign/api/v1/account/signature"
| signPassword | password |
And the response should have a status code 200
Expand All @@ -56,7 +56,7 @@ Feature: account/signature
Given user "signer1" exists
And set the email of user "signer1" to "[email protected]"
And as user "signer1"
And run the command "libresign:configure:openssl --cn=Common\ Name --c=BR --o=Organization --st=State\ of\ Company --l=City\ Name"
And run the command "libresign:configure:openssl --cn=Common\ Name --c=BR --o=Organization --st=State\ of\ Company --l=City\ Name" with result code 0
And sending "post" to ocs "/apps/libresign/api/v1/account/signature"
| signPassword | password |
And the response should have a status code 200
Expand All @@ -76,7 +76,7 @@ Feature: account/signature
| (jq).extensions | (jq).subjectKeyIdentifier != "" |

Scenario: Upload PFX file with error
Given run the command "libresign:configure:openssl --cn=Common\ Name --c=BR --o=Organization --st=State\ of\ Company --l=City\ Name"
Given run the command "libresign:configure:openssl --cn=Common\ Name --c=BR --o=Organization --st=State\ of\ Company --l=City\ Name" with result code 0
And user "signer1" exists
And as user "signer1"
When sending "post" to ocs "/apps/libresign/api/v1/account/pfx"
Expand All @@ -86,7 +86,7 @@ Feature: account/signature
| message | No certificate file provided |

Scenario: Change pfx password with success
Given run the command "libresign:configure:openssl --cn=Common\ Name --c=BR --o=Organization --st=State\ of\ Company --l=City\ Name"
Given run the command "libresign:configure:openssl --cn=Common\ Name --c=BR --o=Organization --st=State\ of\ Company --l=City\ Name" with result code 0
And user "signer1" exists
And as user "signer1"
And sending "post" to ocs "/apps/libresign/api/v1/account/signature"
Expand All @@ -108,7 +108,7 @@ Feature: account/signature
| message | New password to sign documents has been created |

Scenario: Delete pfx password with success
Given run the command "libresign:configure:openssl --cn=Common\ Name --c=BR --o=Organization --st=State\ of\ Company --l=City\ Name"
Given run the command "libresign:configure:openssl --cn=Common\ Name --c=BR --o=Organization --st=State\ of\ Company --l=City\ Name" with result code 0
And user "signer1" exists
And as user "signer1"
And sending "post" to ocs "/apps/libresign/api/v1/account/signature"
Expand Down
18 changes: 15 additions & 3 deletions tests/integration/features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,29 @@ public static function BeforeScenario(): void {
}

/**
* @When /^run the command "(?P<command>(?:[^"]|\\")*)"$/
* @When /^run the command "(?P<command>(?:[^"]|\\")*)"$/ with result code 0
*/
public static function runCommand($command): void {
public static function runCommand(string $command): array {
$console = realpath(__DIR__ . '/../../../../../../console.php');
$owner = posix_getpwuid(fileowner($console));
$fullCommand = 'php ' . $console . ' ' . $command;
if (posix_getuid() !== $owner['uid']) {
$fullCommand = 'runuser -u ' . $owner['name'] . ' -- ' . $fullCommand;
}
$fullCommand .= ' 2>&1';
exec($fullCommand, $output);
exec($fullCommand, $output, $resultCode);
return [
'output' => $output,
'resultCode' => $resultCode,
];
}

/**
* @When /^run the command "(?P<command>(?:[^"]|\\")*)" with result code (\d+)$/ with result code 0
*/
public static function runCommandWithResultCode(string $command, int $resultCode = 0): void {
$return = self::runCommand($command);
Assert::assertEquals($resultCode, $return['resultCode']);
}

public function setOpenedEmailStorage(OpenedEmailStorage $storage): void {
Expand Down
10 changes: 5 additions & 5 deletions tests/integration/features/identify-account/search.feature
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ Feature: search
Given as user "admin"
And sending "post" to ocs "/apps/provisioning_api/api/v1/config/apps/libresign/identify_methods"
| value | (string)[{"name":"email","enabled":true}] |
And run the command "group:add request_signature"
And run the command "group:adduser request_signature search-signer1"
And run the command "config:app:set libresign groups_request_sign --type=array --value=[\"request_signature\"]"
And run the command "group:add request_signature" with result code 0
And run the command "group:adduser request_signature search-signer1" with result code 0
And run the command "config:app:set libresign groups_request_sign --type=array --value=[\"request_signature\"]" with result code 0
Given as user "search-signer1"
And set the email of user "search-signer1" to "[email protected]"
And set the display name of user "search-signer1" to "My Name"
Expand All @@ -44,8 +44,8 @@ Feature: search
And the response should be a JSON array with the following mandatory values
| key | value |
| ocs | {"meta":{"status":"ok","statuscode":200,"message":"OK"},"data":[]} |
And run the command "group:delete request_signature"
And run the command "config:app:delete libresign groups_request_sign"
And run the command "group:delete request_signature" with result code 0
And run the command "config:app:delete libresign groups_request_sign" with result code 0
And set the display name of user "search-signer1" to "search-signer1-displayname"

Scenario: Search account by herself with permission to identify by account
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/features/page/index.feature
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Feature: page/sign_identify_default
Background: Make setup ok
Given run the command "config:app:set libresign authkey --value dummy"
Given run the command "config:app:set libresign authkey --value dummy" with result code 0

Scenario: Open sign file with all data valid
Given as user "admin"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Feature: page/sign_identify_account
Background: Make setup ok
Given run the command "config:app:set libresign authkey --value dummy"
Given run the command "config:app:set libresign authkey --value dummy" with result code 0

Scenario: Open sign file with invalid account data
Given user "signer1" exists
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/features/page/validate.feature
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Feature: page/validate
Background: Make setup ok
Given run the command "config:app:set libresign authkey --value dummy"
Given run the command "config:app:set libresign authkey --value dummy" with result code 0

Scenario: Unauthenticated user can see sign page
Given as user "admin"
Expand Down
40 changes: 20 additions & 20 deletions tests/integration/features/sign/request.feature
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Feature: request-signature
Scenario: Get error when try to request to sign isn't manager
Given user "signer1" exists
And as user "signer1"
And run the command "libresign:configure:openssl --cn test"
And run the command "libresign:configure:openssl --cn test" with result code 0
When sending "post" to ocs "/apps/libresign/api/v1/request-signature"
| file | {"base64":""} |
| users | [{"identify":{"account":"signer1"}}] |
Expand All @@ -15,7 +15,7 @@ Feature: request-signature

Scenario: Get error when try to request to sign without file name
Given as user "admin"
And run the command "libresign:configure:openssl --cn test"
And run the command "libresign:configure:openssl --cn test" with result code 0
When sending "post" to ocs "/apps/libresign/api/v1/request-signature"
| file | {"invalid":""} |
| users | [{"identify":{"account":"signer1"}}] |
Expand All @@ -28,7 +28,7 @@ Feature: request-signature
Scenario: Request to sign with error using different authenticated account
Given as user "admin"
And user "signer1" exists
And run the command "libresign:configure:openssl --cn test"
And run the command "libresign:configure:openssl --cn test" with result code 0
And set the email of user "signer1" to "[email protected]"
And reset notifications of user "signer1"
And sending "post" to ocs "/apps/libresign/api/v1/request-signature"
Expand All @@ -50,7 +50,7 @@ Feature: request-signature
Scenario: Request to sign with error when the user is not authenticated
Given as user "admin"
And user "signer1" exists
And run the command "libresign:configure:openssl --cn test"
And run the command "libresign:configure:openssl --cn test" with result code 0
And reset notifications of user "signer1"
And my inbox is empty
And sending "post" to ocs "/apps/libresign/api/v1/request-signature"
Expand All @@ -71,7 +71,7 @@ Feature: request-signature
Scenario: Request to sign with error when the authenticated user have an email different of signer
Given as user "admin"
And user "signer1" exists
And run the command "libresign:configure:openssl --cn test"
And run the command "libresign:configure:openssl --cn test" with result code 0
And reset notifications of user "signer1"
And set the email of user "signer1" to "[email protected]"
And my inbox is empty
Expand All @@ -96,8 +96,8 @@ Feature: request-signature
Scenario: Request to sign with error when the link was expired
Given as user "admin"
And my inbox is empty
And run the command "libresign:configure:openssl --cn test"
And run the command "config:app:set libresign maximum_validity --value 1"
And run the command "libresign:configure:openssl --cn test" with result code 0
And run the command "config:app:set libresign maximum_validity --value 1" with result code 0
When sending "post" to ocs "/apps/libresign/api/v1/request-signature"
| file | {"url":"<BASE_URL>/apps/libresign/develop/pdf"} |
| users | [{"identify":{"email":"signer2@domain.test"}}] |
Expand All @@ -118,7 +118,7 @@ Feature: request-signature
Scenario: Request to sign with success when is necessary to renew the link
Given as user "admin"
And my inbox is empty
And run the command "libresign:configure:openssl --cn test"
And run the command "libresign:configure:openssl --cn test" with result code 0
And sending "post" to ocs "/apps/provisioning_api/api/v1/config/apps/libresign/identify_methods"
| value | (string)[{"name":"email","enabled":true,"mandatory":true,"can_create_account":false}] |
And sending "post" to ocs "/apps/libresign/api/v1/request-signature"
Expand All @@ -130,8 +130,8 @@ Feature: request-signature
And I open the latest email to "[email protected]" with subject "LibreSign: There is a file for you to sign"
And I fetch the signer UUID from opened email
And as user ""
And run the command "config:app:set libresign maximum_validity --value 300"
And run the command "config:app:set libresign renewal_interval --value 1"
And run the command "config:app:set libresign maximum_validity --value 300" with result code 0
And run the command "config:app:set libresign renewal_interval --value 1" with result code 0
Given wait for 2 second
When sending "get" to "/apps/libresign/p/sign/<SIGN_UUID>"
Then the response should have a status code 422
Expand All @@ -152,7 +152,7 @@ Feature: request-signature
# setting the renewal interval to 2 and making 3 requests, one by second,
# the 3rd don't will fail because on each valid request, the renewal
# interval is renewed.
And run the command "config:app:set libresign renewal_interval --value 2"
And run the command "config:app:set libresign renewal_interval --value 2" with result code 0
Given wait for 1 second
When sending "get" to "/apps/libresign/p/sign/<SIGN_UUID>"
And the response should have a status code 200
Expand Down Expand Up @@ -182,7 +182,7 @@ Feature: request-signature
Scenario: Request to sign with success using account as identifier
Given as user "admin"
And user "signer1" exists
And run the command "libresign:configure:openssl --cn test"
And run the command "libresign:configure:openssl --cn test" with result code 0
And set the email of user "signer1" to "[email protected]"
And reset notifications of user "signer1"
And my inbox is empty
Expand All @@ -203,7 +203,7 @@ Feature: request-signature

Scenario: Request to sign with error using account as identifier with invalid email
Given as user "admin"
And run the command "libresign:configure:openssl --cn test"
And run the command "libresign:configure:openssl --cn test" with result code 0
When sending "post" to ocs "/apps/libresign/api/v1/request-signature"
| file | {"url":"<BASE_URL>/apps/libresign/develop/pdf"} |
| users | [{"identify":{"account":"invaliddomain.test"}}] |
Expand All @@ -215,7 +215,7 @@ Feature: request-signature

Scenario: Request to sign with error using email as account identifier
Given as user "admin"
And run the command "libresign:configure:openssl --cn test"
And run the command "libresign:configure:openssl --cn test" with result code 0
When sending "post" to ocs "/apps/libresign/api/v1/request-signature"
| file | {"url":"<BASE_URL>/apps/libresign/develop/pdf"} |
| users | [{"identify":{"account":"signer3@domain.test"}}] |
Expand All @@ -227,7 +227,7 @@ Feature: request-signature

Scenario: Request to sign with success using email as identifier and URL as file
Given as user "admin"
And run the command "libresign:configure:openssl --cn test"
And run the command "libresign:configure:openssl --cn test" with result code 0
And my inbox is empty
When sending "post" to ocs "/apps/libresign/api/v1/request-signature"
| file | {"url":"<BASE_URL>/apps/libresign/develop/pdf"} |
Expand All @@ -240,7 +240,7 @@ Feature: request-signature
Scenario: Request to sign with success using account as identifier and URL as file
Given as user "admin"
And user "signer1" exists
And run the command "libresign:configure:openssl --cn test"
And run the command "libresign:configure:openssl --cn test" with result code 0
And set the email of user "signer1" to "[email protected]"
And reset notifications of user "signer1"
And my inbox is empty
Expand All @@ -258,7 +258,7 @@ Feature: request-signature

Scenario: Request to sign with success using email as identifier
Given as user "admin"
And run the command "libresign:configure:openssl --cn test"
And run the command "libresign:configure:openssl --cn test" with result code 0
And set the email of user "signer1" to "[email protected]"
And my inbox is empty
When sending "post" to ocs "/apps/libresign/api/v1/request-signature"
Expand All @@ -271,7 +271,7 @@ Feature: request-signature

Scenario: Request to sign using email as identifier and when is necessary to use visible elements
Given as user "admin"
And run the command "libresign:configure:openssl --cn test"
And run the command "libresign:configure:openssl --cn test" with result code 0
And sending "post" to ocs "/apps/provisioning_api/api/v1/config/apps/libresign/identify_methods"
| value | (string)[{"name":"email","enabled":true,"mandatory":true,"can_create_account":false}] |
And I send a file to be signed
Expand Down Expand Up @@ -299,7 +299,7 @@ Feature: request-signature
Scenario: Request to sign with success using multiple users
Given as user "admin"
And user "signer1" exists
And run the command "libresign:configure:openssl --cn test"
And run the command "libresign:configure:openssl --cn test" with result code 0
And set the email of user "signer1" to "[email protected]"
And my inbox is empty
When sending "post" to ocs "/apps/libresign/api/v1/request-signature"
Expand All @@ -316,7 +316,7 @@ Feature: request-signature
And I open the latest email to "[email protected]" with subject "LibreSign: There is a file for you to sign"

Scenario: CRUD of identify methods
Given run the command "libresign:configure:openssl --cn test"
Given run the command "libresign:configure:openssl --cn test" with result code 0
And user "signer1" exists
And as user "admin"
When I send a file to be signed
Expand Down

0 comments on commit 666d611

Please sign in to comment.