Skip to content

Commit

Permalink
Include the token of shares with public rooms in share API responses
Browse files Browse the repository at this point in the history
Only shares with public rooms can be accessed using the token, so there
is no point in returning the token for shares with other types of rooms.

Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
  • Loading branch information
danxuliu authored and nickvergessen committed Aug 24, 2018
1 parent 1dc87c7 commit e273ac4
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/Share/Helper/ShareAPIController.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ public function formatShare(IShare $share): array {

$result['share_with_displayname'] = $roomName;

if ($room->getType() === Room::PUBLIC_CALL) {
$result['token'] = $share->getToken();
}

return $result;
}

Expand Down
4 changes: 4 additions & 0 deletions tests/integration/features/bootstrap/SharingContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,10 @@ private function assertFieldIsInReturnedShare(string $field, string $contentExpe

if ($contentExpected === 'A_NUMBER') {
PHPUnit_Framework_Assert::assertTrue(is_numeric((string)$returnedShare->$field), "Field '$field' is not a number: " . $returnedShare->$field);
} else if ($contentExpected === 'A_TOKEN') {
// A token is composed by 15 characters from
// ISecureRandom::CHAR_HUMAN_READABLE.
PHPUnit_Framework_Assert::assertRegExp('/^[abcdefgijkmnopqrstwxyzABCDEFGHJKLMNPQRSTWXYZ23456789]{15}$/', (string)$returnedShare->$field, "Field '$field' is not a token");
} else if (strpos($contentExpected, 'REGEXP ') === 0) {
PHPUnit_Framework_Assert::assertRegExp(substr($contentExpected, strlen('REGEXP ')), (string)$returnedShare->$field, "Field '$field' does not match");
} else {
Expand Down
9 changes: 9 additions & 0 deletions tests/integration/features/sharing/create.feature
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ Feature: create
| file_target | /welcome.txt |
| share_with | own public room |
| share_with_displayname | Own public room |
| token | A_TOKEN |
And user "participant2" gets last share
And share is returned with
| uid_owner | participant1 |
Expand All @@ -181,6 +182,7 @@ Feature: create
| file_target | /welcome (2).txt |
| share_with | own public room |
| share_with_displayname | Own public room |
| token | A_TOKEN |
And user "participant3" gets last share
And share is returned with
| uid_owner | participant1 |
Expand All @@ -192,6 +194,7 @@ Feature: create
| file_target | /welcome (2).txt |
| share_with | own public room |
| share_with_displayname | Own public room |
| token | A_TOKEN |

Scenario: create share with a public room invited to
Given user "participant2" creates room "public room invited to"
Expand All @@ -210,6 +213,7 @@ Feature: create
| file_target | /welcome.txt |
| share_with | public room invited to |
| share_with_displayname | Public room invited to |
| token | A_TOKEN |
And user "participant2" gets last share
And share is returned with
| uid_owner | participant1 |
Expand All @@ -221,6 +225,7 @@ Feature: create
| file_target | /welcome (2).txt |
| share_with | public room invited to |
| share_with_displayname | Public room invited to |
| token | A_TOKEN |
And user "participant3" gets last share
And share is returned with
| uid_owner | participant1 |
Expand All @@ -232,6 +237,7 @@ Feature: create
| file_target | /welcome (2).txt |
| share_with | public room invited to |
| share_with_displayname | Public room invited to |
| token | A_TOKEN |

Scenario: create share with a public room self joined to
Given user "participant2" creates room "public room self joined to"
Expand All @@ -250,6 +256,7 @@ Feature: create
| file_target | /welcome.txt |
| share_with | public room self joined to |
| share_with_displayname | Public room self joined to |
| token | A_TOKEN |
And user "participant2" gets last share
And share is returned with
| uid_owner | participant1 |
Expand All @@ -261,6 +268,7 @@ Feature: create
| file_target | /welcome (2).txt |
| share_with | public room self joined to |
| share_with_displayname | Public room self joined to |
| token | A_TOKEN |
And user "participant3" gets last share
And share is returned with
| uid_owner | participant1 |
Expand All @@ -272,6 +280,7 @@ Feature: create
| file_target | /welcome (2).txt |
| share_with | public room self joined to |
| share_with_displayname | Public room self joined to |
| token | A_TOKEN |

Scenario: create share with a public room not joined to
Given user "participant2" creates room "public room not joined to"
Expand Down
2 changes: 2 additions & 0 deletions tests/integration/features/sharing/delete.feature
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ Feature: delete
| file_target | /welcome.txt |
| share_with | public room not joined to |
| share_with_displayname | Public room not joined to |
| token | A_TOKEN |
And user "participant3" gets last share
And share is returned with
| uid_owner | participant2 |
Expand All @@ -201,6 +202,7 @@ Feature: delete
| file_target | /welcome (2).txt |
| share_with | public room not joined to |
| share_with_displayname | Public room not joined to |
| token | A_TOKEN |



Expand Down
7 changes: 7 additions & 0 deletions tests/integration/features/sharing/hooks.feature
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Feature: hooks
| file_target | /welcome (2).txt |
| share_with | public room |
| share_with_displayname | Public room |
| token | A_TOKEN |



Expand Down Expand Up @@ -116,6 +117,7 @@ Feature: hooks
| file_target | /welcome (2).txt |
| share_with | public room |
| share_with_displayname | Public room |
| token | A_TOKEN |
And user "participant2" gets last share
And share is returned with
| uid_owner | participant2 |
Expand All @@ -127,6 +129,7 @@ Feature: hooks
| file_target | /welcome.txt |
| share_with | public room |
| share_with_displayname | Public room |
| token | A_TOKEN |

Scenario: leave public room self joined to after sharing a file
Given user "participant1" creates room "public room"
Expand Down Expand Up @@ -318,6 +321,7 @@ Feature: hooks
| file_target | /welcome.txt |
| share_with | public room |
| share_with_displayname | Public room |
| token | A_TOKEN |
And user "participant2" gets last share
And the OCS status code should be "404"

Expand All @@ -340,6 +344,7 @@ Feature: hooks
| file_target | /welcome.txt |
| share_with | public room |
| share_with_displayname | Public room |
| token | A_TOKEN |
And user "participant2" gets last share
And the OCS status code should be "404"

Expand Down Expand Up @@ -611,6 +616,7 @@ Feature: hooks
| file_target | /welcome (2).txt |
| share_with | public room |
| share_with_displayname | Public room |
| token | A_TOKEN |

Scenario: join sharee again to public room after a file was shared and moved by the sharee and the sharee left the room
Given user "participant1" creates room "public room"
Expand All @@ -633,6 +639,7 @@ Feature: hooks
| file_target | /welcome (2).txt |
| share_with | public room |
| share_with_displayname | Public room |
| token | A_TOKEN |



Expand Down
28 changes: 28 additions & 0 deletions tests/integration/features/sharing/update.feature
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ Feature: update
| file_target | /welcome.txt |
| share_with | own public room |
| share_with_displayname | Own public room |
| token | A_TOKEN |
| permissions | 1 |
| expiration | +3 days |
And user "participant1" gets last share
Expand All @@ -228,6 +229,7 @@ Feature: update
| file_target | /welcome.txt |
| share_with | own public room |
| share_with_displayname | Own public room |
| token | A_TOKEN |
| permissions | 1 |
| expiration | +3 days |
And user "participant2" gets last share
Expand All @@ -241,6 +243,7 @@ Feature: update
| file_target | /welcome (2).txt |
| share_with | own public room |
| share_with_displayname | Own public room |
| token | A_TOKEN |
| permissions | 1 |
| expiration | +3 days |
And user "participant3" gets last share
Expand All @@ -254,6 +257,7 @@ Feature: update
| file_target | /welcome (2).txt |
| share_with | own public room |
| share_with_displayname | Own public room |
| token | A_TOKEN |
| permissions | 1 |
| expiration | +3 days |

Expand All @@ -277,6 +281,7 @@ Feature: update
| file_target | /welcome.txt |
| share_with | public room invited to |
| share_with_displayname | Public room invited to |
| token | A_TOKEN |
| permissions | 1 |
| expiration | +3 days |
And user "participant1" gets last share
Expand All @@ -290,6 +295,7 @@ Feature: update
| file_target | /welcome.txt |
| share_with | public room invited to |
| share_with_displayname | Public room invited to |
| token | A_TOKEN |
| permissions | 1 |
| expiration | +3 days |
And user "participant2" gets last share
Expand All @@ -303,6 +309,7 @@ Feature: update
| file_target | /welcome (2).txt |
| share_with | public room invited to |
| share_with_displayname | Public room invited to |
| token | A_TOKEN |
| permissions | 1 |
| expiration | +3 days |
And user "participant3" gets last share
Expand All @@ -316,6 +323,7 @@ Feature: update
| file_target | /welcome (2).txt |
| share_with | public room invited to |
| share_with_displayname | Public room invited to |
| token | A_TOKEN |
| permissions | 1 |
| expiration | +3 days |

Expand All @@ -339,6 +347,7 @@ Feature: update
| file_target | /welcome.txt |
| share_with | public room self joined to |
| share_with_displayname | Public room self joined to |
| token | A_TOKEN |
| permissions | 1 |
| expiration | +3 days |
And user "participant1" gets last share
Expand All @@ -352,6 +361,7 @@ Feature: update
| file_target | /welcome.txt |
| share_with | public room self joined to |
| share_with_displayname | Public room self joined to |
| token | A_TOKEN |
| permissions | 1 |
| expiration | +3 days |
And user "participant2" gets last share
Expand All @@ -365,6 +375,7 @@ Feature: update
| file_target | /welcome (2).txt |
| share_with | public room self joined to |
| share_with_displayname | Public room self joined to |
| token | A_TOKEN |
| permissions | 1 |
| expiration | +3 days |
And user "participant3" gets last share
Expand All @@ -378,6 +389,7 @@ Feature: update
| file_target | /welcome (2).txt |
| share_with | public room self joined to |
| share_with_displayname | Public room self joined to |
| token | A_TOKEN |
| permissions | 1 |
| expiration | +3 days |

Expand Down Expand Up @@ -472,6 +484,7 @@ Feature: update
| file_target | /welcome.txt |
| share_with | public room not joined to |
| share_with_displayname | Public room not joined to |
| token | A_TOKEN |
And user "participant3" gets last share
And share is returned with
| uid_owner | participant2 |
Expand All @@ -483,6 +496,7 @@ Feature: update
| file_target | /welcome (2).txt |
| share_with | public room not joined to |
| share_with_displayname | Public room not joined to |
| token | A_TOKEN |



Expand Down Expand Up @@ -749,6 +763,7 @@ Feature: update
| file_target | /welcome (2).txt |
| share_with | own public room |
| share_with_displayname | Own public room |
| token | A_TOKEN |
| permissions | 1 |
| expiration | +3 days |
And user "participant1" gets last share
Expand All @@ -762,6 +777,7 @@ Feature: update
| file_target | /welcome.txt |
| share_with | own public room |
| share_with_displayname | Own public room |
| token | A_TOKEN |
| permissions | 1 |
| expiration | +3 days |
And user "participant2" gets last share
Expand All @@ -775,6 +791,7 @@ Feature: update
| file_target | /welcome (2).txt |
| share_with | own public room |
| share_with_displayname | Own public room |
| token | A_TOKEN |
| permissions | 1 |
| expiration | +3 days |
And user "participant3" gets last share
Expand All @@ -788,6 +805,7 @@ Feature: update
| file_target | /welcome (2).txt |
| share_with | own public room |
| share_with_displayname | Own public room |
| token | A_TOKEN |
| permissions | 1 |
| expiration | +3 days |

Expand All @@ -811,6 +829,7 @@ Feature: update
| file_target | /welcome (2).txt |
| share_with | public room invited to |
| share_with_displayname | Public room invited to |
| token | A_TOKEN |
| permissions | 1 |
| expiration | +3 days |
And user "participant1" gets last share
Expand All @@ -824,6 +843,7 @@ Feature: update
| file_target | /welcome.txt |
| share_with | public room invited to |
| share_with_displayname | Public room invited to |
| token | A_TOKEN |
| permissions | 1 |
| expiration | +3 days |
And user "participant2" gets last share
Expand All @@ -837,6 +857,7 @@ Feature: update
| file_target | /welcome (2).txt |
| share_with | public room invited to |
| share_with_displayname | Public room invited to |
| token | A_TOKEN |
| permissions | 1 |
| expiration | +3 days |
And user "participant3" gets last share
Expand All @@ -850,6 +871,7 @@ Feature: update
| file_target | /welcome (2).txt |
| share_with | public room invited to |
| share_with_displayname | Public room invited to |
| token | A_TOKEN |
| permissions | 1 |
| expiration | +3 days |

Expand All @@ -873,6 +895,7 @@ Feature: update
| file_target | /welcome (2).txt |
| share_with | public room self joined to |
| share_with_displayname | Public room self joined to |
| token | A_TOKEN |
| permissions | 1 |
| expiration | +3 days |
And user "participant1" gets last share
Expand All @@ -886,6 +909,7 @@ Feature: update
| file_target | /welcome.txt |
| share_with | public room self joined to |
| share_with_displayname | Public room self joined to |
| token | A_TOKEN |
| permissions | 1 |
| expiration | +3 days |
And user "participant2" gets last share
Expand All @@ -899,6 +923,7 @@ Feature: update
| file_target | /welcome (2).txt |
| share_with | public room self joined to |
| share_with_displayname | Public room self joined to |
| token | A_TOKEN |
| permissions | 1 |
| expiration | +3 days |
And user "participant3" gets last share
Expand All @@ -912,6 +937,7 @@ Feature: update
| file_target | /welcome (2).txt |
| share_with | public room self joined to |
| share_with_displayname | Public room self joined to |
| token | A_TOKEN |
| permissions | 1 |
| expiration | +3 days |

Expand Down Expand Up @@ -939,6 +965,7 @@ Feature: update
| file_target | /welcome.txt |
| share_with | public room no longer joined to |
| share_with_displayname | Public room no longer joined to |
| token | A_TOKEN |
And user "participant2" gets last share
And the OCS status code should be "404"
And the HTTP status code should be "200"
Expand All @@ -953,6 +980,7 @@ Feature: update
| file_target | /welcome (2).txt |
| share_with | public room no longer joined to |
| share_with_displayname | Public room no longer joined to |
| token | A_TOKEN |



Expand Down

0 comments on commit e273ac4

Please sign in to comment.