Skip to content

Commit 771c5ec

Browse files
Merge pull request #91 from LibreSign/chore/validate-owner-of-file
chore: valdiate owner of file
2 parents e4e08f2 + d52be92 commit 771c5ec

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

src/NextcloudApiContext.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
use Behat\Behat\Context\Context;
66
use Behat\Gherkin\Node\PyStringNode;
77
use Behat\Gherkin\Node\TableNode;
8+
use Behat\Testwork\Hook\Scope\BeforeSuiteScope;
89
use DOMDocument;
10+
use Exception;
911
use GuzzleHttp\Client;
1012
use GuzzleHttp\Cookie\CookieJar;
1113
use GuzzleHttp\Exception\ClientException;
@@ -46,6 +48,21 @@ public function __construct(?array $parameters = []) {
4648
}
4749
}
4850

51+
/**
52+
* @BeforeSuite
53+
*/
54+
public static function beforeSuite(BeforeSuiteScope $scope):void {
55+
$whoami = (string) exec('whoami');
56+
if (get_current_user() !== $whoami) {
57+
$command = implode(' ', $_SERVER['argv'] ?? []);
58+
throw new Exception(sprintf(
59+
"Have files that %s is the owner and the user that is running this test is %s, is necessary to be the same user.\n" .
60+
"You should run the follow command:\n" .
61+
"runuser -u %s -- %s\n\n",
62+
get_current_user(), $whoami, get_current_user(), $command));
63+
}
64+
}
65+
4966
/**
5067
* @BeforeScenario
5168
*/

0 commit comments

Comments
 (0)