[tests-only][full-ci] test: add test for public link brute-force protection (#13008)
test: add test for public link brute-force protection Signed-off-by: Prajwol Amatya <prajwolamatya11@gmail.com>
This commit is contained in:
1 parent
dbf40a3dcd
commit
52891efd4e
5 files changed
+169
-16
No files matched your search
@@ -324,6 +324,24 @@ class ArchiverContext implements Context {
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private array $publicLinkArchiveData = [];
|
||||
|
||||
/**
|
||||
* @param string $password
|
||||
*
|
||||
* @return array
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
private function getPublicLinkArchiveData(string $password): array {
|
||||
if ($this->publicLinkArchiveData === []) {
|
||||
$this->publicLinkArchiveData = $this->fetchPublicLinkArchiveData($password);
|
||||
}
|
||||
return $this->publicLinkArchiveData;
|
||||
}
|
||||
|
||||
/**
|
||||
* @When /^the public downloads the archive of the last created public link with password "([^"]*)"$/
|
||||
*
|
||||
@@ -334,7 +352,7 @@ class ArchiverContext implements Context {
|
||||
* @throws GuzzleException|Exception
|
||||
*/
|
||||
public function publicDownloadsTheArchiveOfTheLastCreatedPublicLink(string $password = ""): void {
|
||||
$data = $this->fetchPublicLinkArchiveData($password);
|
||||
$data = $this->getPublicLinkArchiveData($password);
|
||||
$fileIds = $data['fileIds'];
|
||||
$signature = $data['signature'];
|
||||
$expiration = $data['expiration'];
|
||||
@@ -360,6 +378,36 @@ class ArchiverContext implements Context {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @When the public downloads the archive of the last created public link with incorrect password :password
|
||||
*
|
||||
* @param string $password
|
||||
*
|
||||
* @return void
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function publicDownloadsTheArchiveOfTheLastCreatedPublicLinkUsingBasicAuth(string $password): void {
|
||||
$data = $this->getPublicLinkArchiveData('%public%');
|
||||
$fileIds = $data['fileIds'];
|
||||
|
||||
$token = $this->featureContext->isUsingSharingNG()
|
||||
? $this->featureContext->shareNgGetLastCreatedLinkShareToken()
|
||||
: $this->featureContext->getLastCreatedPublicShareToken();
|
||||
|
||||
$queryParts = ['public-token=' . urlencode($token)];
|
||||
foreach ($fileIds as $fileId) {
|
||||
$queryParts[] = "id=" . urlencode($fileId);
|
||||
}
|
||||
|
||||
$this->featureContext->setResponse(
|
||||
HttpRequestHelper::get(
|
||||
$this->getArchiverUrl(\implode('&', $queryParts)),
|
||||
'public',
|
||||
$password,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then the downloaded :type archive should contain these files:
|
||||
*
|
||||
|
||||
@@ -1328,6 +1328,30 @@ class FeatureContext extends BehatVariablesContext {
|
||||
$this->setResponse($this->sendingToWithDirectUrl($user, $verb, $endpoint));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $method
|
||||
* @param string $url
|
||||
* @param string $password
|
||||
*
|
||||
* @return ResponseInterface
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
private function sendHttpMethodToUrlWithPassword(string $method, string $url, string $password): ResponseInterface {
|
||||
$password = $this->getActualPassword($password);
|
||||
$token = $this->shareNgGetLastCreatedLinkShareToken();
|
||||
$fullUrl = $this->getBaseUrl() . $url;
|
||||
$headers = [
|
||||
'Public-Token' => $token,
|
||||
];
|
||||
return HttpRequestHelper::sendRequest(
|
||||
$fullUrl,
|
||||
$method,
|
||||
"public",
|
||||
$password,
|
||||
$headers,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @When the public sends HTTP method :method to URL :url with password :password
|
||||
*
|
||||
@@ -1336,23 +1360,33 @@ class FeatureContext extends BehatVariablesContext {
|
||||
* @param string $password
|
||||
*
|
||||
* @return void
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function thePublicSendsHttpMethodToUrlWithPassword(string $method, string $url, string $password): void {
|
||||
$password = $this->getActualPassword($password);
|
||||
$token = $this->shareNgGetLastCreatedLinkShareToken();
|
||||
$fullUrl = $this->getBaseUrl() . $url;
|
||||
$headers = [
|
||||
'Public-Token' => $token,
|
||||
];
|
||||
$this->setResponse(
|
||||
HttpRequestHelper::sendRequest(
|
||||
$fullUrl,
|
||||
$method,
|
||||
"public",
|
||||
$password,
|
||||
$headers,
|
||||
),
|
||||
);
|
||||
$this->setResponse($this->sendHttpMethodToUrlWithPassword($method, $url, $password));
|
||||
}
|
||||
|
||||
/**
|
||||
* @When the public sends HTTP method :method to URL :url with password :password for :attempts times
|
||||
*
|
||||
* @param string $method
|
||||
* @param string $url
|
||||
* @param string $password
|
||||
* @param int $attempts
|
||||
*
|
||||
* @return void
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function thePublicSendsHttpMethodToUrlWithPasswordForTimes(
|
||||
string $method,
|
||||
string $url,
|
||||
string $password,
|
||||
int $attempts,
|
||||
): void {
|
||||
for ($i = 0; $i < $attempts; $i++) {
|
||||
$this->setResponse($this->sendHttpMethodToUrlWithPassword($method, $url, $password));
|
||||
$this->pushToLastHttpStatusCodesArray();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -469,6 +469,7 @@ default:
|
||||
- SharingNgContext:
|
||||
- CollaborationContext:
|
||||
- TrashbinContext:
|
||||
- OcisConfigContext:
|
||||
|
||||
apiServiceAvailability:
|
||||
paths:
|
||||
|
||||
@@ -1220,3 +1220,26 @@ Feature: collaboration (wopi)
|
||||
| app | FakeOffice |
|
||||
When the public sends a lock request with lock id "abcdef123" to the last opened file using wopi endpoint
|
||||
Then the HTTP status code should be "200"
|
||||
|
||||
|
||||
Scenario: brute-force protection must apply to max failed attempt on /app/open
|
||||
And user "Alice" has uploaded file "filesForUpload/simple.odt" to "simple.odt"
|
||||
And we save it into "FILEID"
|
||||
And user "Alice" has created the following resource link share:
|
||||
| resource | simple.odt |
|
||||
| space | Personal |
|
||||
| permissionsRole | View |
|
||||
| password | %public% |
|
||||
When the public sends HTTP method "POST" to URL "/app/open?file_id=<<FILEID>>" with password "%public%"
|
||||
Then the HTTP status code should be "200"
|
||||
# For this test using the default STORAGE_PUBLICLINK_BRUTEFORCE_MAXATTEMPTS (5)
|
||||
# instead of lowering it via an env-config restart: a restart wipes oCIS's in-memory,
|
||||
# non-persistent app registry, and the FakeOffice/Collabora/OnlyOffice app providers this
|
||||
# suite depends on only ever register once, at their own startup - they never
|
||||
# re-register - so losing that registration here would permanently break every other
|
||||
# scenario in this file for the rest of the test run
|
||||
# After the exceeding max attempts the public request to /app/open with correct password should return 401
|
||||
When the public sends HTTP method "POST" to URL "/app/open?file_id=<<FILEID>>" with password "wrong-pw" for 6 times
|
||||
Then the HTTP status code of responses on each endpoint should be "401, 401, 401, 401, 401, 401" respectively
|
||||
When the public sends HTTP method "POST" to URL "/app/open?file_id=<<FILEID>>" with password "%public%"
|
||||
Then the HTTP status code should be "401"
|
||||
@@ -0,0 +1,47 @@
|
||||
@env-config
|
||||
Feature: brute-force protection for password protected public links
|
||||
As the maintainer of a password protected public link
|
||||
I want repeated wrong password guesses against that link to be rate limited
|
||||
So that an attacker cannot brute-force the password regardless of which endpoint they use
|
||||
|
||||
Background:
|
||||
Given these users have been created with default attributes:
|
||||
| username |
|
||||
| Alice |
|
||||
And using spaces DAV path
|
||||
And the config "STORAGE_PUBLICLINK_BRUTEFORCE_MAXATTEMPTS" has been set to "2" for "storage-publiclink" service
|
||||
And using SharingNG
|
||||
|
||||
|
||||
Scenario: brute-force protection must apply to max failed attempt on public WebDAV
|
||||
Given user "Alice" has uploaded file with content "some content" to "testfile.txt"
|
||||
When user "Alice" creates the following resource link share using the Graph API:
|
||||
| resource | testfile.txt |
|
||||
| space | Personal |
|
||||
| permissionsRole | View |
|
||||
| password | %public% |
|
||||
Then the public download of file "testfile.txt" from inside the last public link shared folder using the public WebDAV API with password "%public%" should fail with HTTP status code "200"
|
||||
And the public download of file "testfile.txt" from inside the last public link shared folder using the public WebDAV API with password "wrong-password" should fail with HTTP status code "401"
|
||||
And the public download of file "testfile.txt" from inside the last public link shared folder using the public WebDAV API with password "wrong-password" should fail with HTTP status code "401"
|
||||
And the public download of file "testfile.txt" from inside the last public link shared folder using the public WebDAV API with password "wrong-password" should fail with HTTP status code "429"
|
||||
And the public download of file "testfile.txt" from inside the last public link shared folder using the public WebDAV API with password "%public%" should fail with HTTP status code "429"
|
||||
|
||||
|
||||
Scenario: brute-force protection must apply to max failed attempt on /archiver
|
||||
Given user "Alice" has created folder "public-folder"
|
||||
And user "Alice" has uploaded file with content "some content" to "public-folder/testfile.txt"
|
||||
And user "Alice" has created the following resource link share:
|
||||
| resource | public-folder |
|
||||
| space | Personal |
|
||||
| permissionsRole | View |
|
||||
| password | %public% |
|
||||
When the public downloads the archive of the last created public link with password "%public%"
|
||||
Then the HTTP status code should be "200"
|
||||
When the public downloads the archive of the last created public link with incorrect password "wrong-pw"
|
||||
Then the HTTP status code should be "401"
|
||||
When the public downloads the archive of the last created public link with incorrect password "wrong-pw"
|
||||
Then the HTTP status code should be "401"
|
||||
When the public downloads the archive of the last created public link with incorrect password "wrong-pw"
|
||||
Then the HTTP status code should be "401"
|
||||
When the public downloads the archive of the last created public link with password "%public%"
|
||||
Then the HTTP status code should be "401"
|
||||
Reference in new issue
Block a user