Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 105 additions & 0 deletions tests/acceptance/TestHelpers/GraphHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2468,4 +2468,109 @@ public static function getAllUsers(
self::getRequestHeaders()
);
}

/**
* @param string $baseUrl
* @param string $xRequestId
* @param string $user
* @param string $password
* @param string $source
*
* @return ResponseInterface
* @throws GuzzleException
*/
public static function addUserPhoto(
string $baseUrl,
string $xRequestId,
string $user,
string $password,
string $source
): ResponseInterface {
$url = self::getFullUrl($baseUrl, "me/photo/\$value");
return HttpRequestHelper::put(
$url,
$xRequestId,
$user,
$password,
['Content-Type' => 'image/jpeg'],
$source
);
}

/**
* @param string $baseUrl
* @param string $xRequestId
* @param string $user
* @param string $password
*
* @return ResponseInterface
* @throws GuzzleException
*/
public static function getUserPhoto(
string $baseUrl,
string $xRequestId,
string $user,
string $password
): ResponseInterface {
$url = self::getFullUrl($baseUrl, "me/photo/\$value");
return HttpRequestHelper::get(
$url,
$xRequestId,
$user,
$password
);
}

/**
* @param string $baseUrl
* @param string $xRequestId
* @param string $user
* @param string $password
* @param string $source
*
* @return ResponseInterface
* @throws GuzzleException
*/
public static function changeUserPhoto(
string $baseUrl,
string $xRequestId,
string $user,
string $password,
string $source
): ResponseInterface {
$url = self::getFullUrl($baseUrl, "me/photo/\$value");
return HttpRequestHelper::sendRequest(
$url,
$xRequestId,
"PATCH",
$user,
$password,
['Content-Type' => 'image/jpeg'],
$source
);
}

/**
* @param string $baseUrl
* @param string $xRequestId
* @param string $user
* @param string $password
*
* @return ResponseInterface
* @throws GuzzleException
*/
public static function deleteUserPhoto(
string $baseUrl,
string $xRequestId,
string $user,
string $password
): ResponseInterface {
$url = self::getFullUrl($baseUrl, "me/photo/\$value");
return HttpRequestHelper::delete(
$url,
$xRequestId,
$user,
$password
);
}
}
141 changes: 141 additions & 0 deletions tests/acceptance/bootstrap/GraphContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -3178,4 +3178,145 @@ public function theUserGetsAllUsersUsingTheGraphApi(?string $user = null): void

$this->featureContext->setResponse($response);
}

/**
* @When /^user "([^"]*)" sets profile photo to "([^"]*)" using the Graph API$/
*
* @param string $user
* @param string $photo
*
* @return void
* @throws GuzzleException
*/
public function userSetsUserProfilePhotoUsingTheGraphApi(
string $user,
string $photo
): void {
$source = \file_get_contents(
$this->featureContext->acceptanceTestsDirLocation() . $photo
);
$response = GraphHelper::addUserPhoto(
$this->featureContext->getBaseUrl(),
$this->featureContext->getStepLineRef(),
$user,
$this->featureContext->getPasswordForUser($user),
$source
);
$this->featureContext->setResponse($response);
}

/**
* @Given /^user "([^"]*)" has set the profile photo to "([^"]*)"$/
*
* @param string $user
* @param string $photo
*
* @return void
* @throws GuzzleException
* @throws Exception
*/
public function theUserHasSetPhoto(string $user, string $photo): void {
$response = $this->userSetsUserProfilePhotoUsingTheGraphApi($user, $photo);
$this->featureContext->theHTTPStatusCodeShouldBe(200, '', $response);
}

/**
* @When /^user "([^"]*)" (gets|tries to get) a profile photo using the Graph API$/
*
* @param string $user
*
* @return void
* @throws GuzzleException
*/
public function userShouldHasAProfilePhotoUsingTheGraphApi(string $user): void {
$response = GraphHelper::getUserPhoto(
$this->featureContext->getBaseUrl(),
$this->featureContext->getStepLineRef(),
$user,
$this->featureContext->getPasswordForUser($user)
);
$this->featureContext->setResponse($response);
}

/**
* @Then /^the profile photo should contain file "([^"]*)"$/
*
* @param string $file
*
* @return void
* @throws GuzzleException
*/
public function profilePhotoShouldContainFile(string $file): void {
$source = \file_get_contents(
$this->featureContext->acceptanceTestsDirLocation() . $file
);
Assert::assertEquals(
$source,
$this->featureContext->getResponse()->getBody()->getContents(),
"The profile photo binary does not match expected content of $file"
);
}

/**
* @Then /^for user "([^"]*)" the profile photo should contain file "([^"]*)"$/
*
* @param string $user
* @param string $file
*
* @return void
* @throws GuzzleException
*/
public function profilePhotoForUserShouldContainFile(string $user, string $file): void {
$this->featureContext->theHTTPStatusCodeShouldBe(
200,
"Expected response status code should be 200",
$this->userShouldHasAProfilePhotoUsingTheGraphApi($user)
);
$this->profilePhotoShouldContainFile($file);
}

/**
* @When /^user "([^"]*)" changes the profile photo to "([^"]*)" using the Graph API$/
*
* @param string $user
* @param string $photo
*
* @return void
* @throws GuzzleException
*/
public function userChangesUserProfilePhotoUsingTheGraphApi(
string $user,
string $photo
): void {
$source = \file_get_contents(
$this->featureContext->acceptanceTestsDirLocation() . $photo
);
$response = GraphHelper::changeUserPhoto(
$this->featureContext->getBaseUrl(),
$this->featureContext->getStepLineRef(),
$user,
$this->featureContext->getPasswordForUser($user),
$source
);
$this->featureContext->setResponse($response);
}

/**
* @When /^user "([^"]*)" deletes the profile photo using the Graph API$/
*
* @param string $user
*
* @return void
* @throws GuzzleException
*/
public function userDeletesAProfilePhotoUsingTheGraphApi(string $user): void {
$response = GraphHelper::deleteUserPhoto(
$this->featureContext->getBaseUrl(),
$this->featureContext->getStepLineRef(),
$user,
$this->featureContext->getPasswordForUser($user)
);
$this->featureContext->setResponse($response);
}

}
10 changes: 10 additions & 0 deletions tests/acceptance/features/apiAntivirus/antivirus.feature
Original file line number Diff line number Diff line change
Expand Up @@ -481,3 +481,13 @@ Feature: antivirus
| Virus found in text.txt. Upload not possible. Virus: Eicar-Signature |
And for user "Brian" the content of the file "/text.txt" of the space "new-space" should be "hello world"
And for user "Alice" the content of the file "/text.txt" of the space "new-space" should be "hello world"


Scenario Outline: try adding a photo of the user containing the virus
When user "Alice" sets profile photo to "filesForUpload/filesWithVirus/eicar-image.jpeg" using the Graph API
Then the HTTP status code should be "200"
And user "Alice" should get a notification with subject "Virus found" and message:
| message |
| Virus found in eicar-image.jpeg. Upload not possible. Virus: Eicar-Signature |
When user "Alice" tries to get a profile photo using the Graph API
Then the HTTP status code should be "404"
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
Feature: user profile photo
As a user, I want to provide my avatar to make my actions more visible

Background:
Given user "Alice" has been created with default attributes


Scenario Outline: add profile photo
When user "Alice" sets profile photo to "<file>" using the Graph API
Then the HTTP status code should be "<http-status-code>"
And for user "Alice" the profile photo should contain file "<file>"
Examples:
| file | http-status-code |
| filesForUpload/testavatar.jpg | 200 |
| filesForUpload/testavatar.png | 200 |
| filesForUpload/example.gif | 200 |
| filesForUpload/lorem.txt | 400 |
| filesForUpload/simple.pdf | 400 |
| filesForUpload/broken-image-file.png | 400 |


Scenario: user tries to get profile photo when none is set
When user "Alice" tries to get a profile photo using the Graph API
Then the HTTP status code should be "404"


Scenario Outline: get profile photo
Given user "Alice" has set the profile photo to "<file>"
When user "Alice" gets a profile photo using the Graph API
Then the HTTP status code should be "200"
And the profile photo should contain file "<file>"
Examples:
| file |
| filesForUpload/testavatar.jpg |
| filesForUpload/testavatar.png |
| filesForUpload/example.gif |


Scenario Outline: change profile photo
Given user "Alice" has set the profile photo to "filesForUpload/testavatar.jpg"
When user "Alice" changes the profile photo to "<file>" using the Graph API
Then the HTTP status code should be "<http-status-code>"
And for user "Alice" the profile photo should contain file "<file>"
Examples:
| file | http-status-code |
| filesForUpload/testavatar.jpg | 200 |
| filesForUpload/testavatar.png | 200 |
| filesForUpload/example.gif | 200 |
| filesForUpload/lorem.txt | 400 |
| filesForUpload/simple.pdf | 400 |
| filesForUpload/broken-image-file.png | 400 |


Scenario Outline: delete profile photo
Given user "Alice" has set the profile photo to "<file>"
When user "Alice" deletes the profile photo using the Graph API
Then the HTTP status code should be "200"
When user "Alice" tries to get a profile photo using the Graph API
Then the HTTP status code should be "404"
Examples:
| file |
| filesForUpload/testavatar.jpg |
| filesForUpload/testavatar.png |
| filesForUpload/example.gif |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.