-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test for a openidish mechanism for proving to third parties that … (
#234) * Add test for a openidish mechanism for proving to third parties that you own a given user_id * Add tests for missing and invalid tokens * Rename openid/token to openid/request_token
- Loading branch information
1 parent
691813e
commit 995c37d
Showing
1 changed file
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
test "Can generate a openid access_token that can be exchanged for information about a user", | ||
requires => [ local_user_fixture(), $main::HTTP_CLIENT, $main::HOMESERVER_INFO[0] ], | ||
|
||
check => sub { | ||
my ( $user, $http, $info ) = @_; | ||
|
||
do_request_json_for( $user, | ||
method => "POST", | ||
uri => "/r0/user/:user_id/openid/request_token", | ||
content => {}, | ||
)->then( sub { | ||
my ( $body ) = @_; | ||
|
||
assert_json_keys( $body, qw( access_token matrix_server_name expires_in ) ); | ||
assert_eq( $body->{matrix_server_name}, $info->server_name ); | ||
|
||
my $token = $body->{access_token}; | ||
|
||
$http->do_request_json( | ||
method => "GET", | ||
uri => $info->client_location . "/_matrix/federation/v1/openid/userinfo", | ||
params => { access_token => $token }, | ||
); | ||
})->then( sub { | ||
my ( $body ) = @_; | ||
|
||
assert_json_keys( $body, qw( sub ) ); | ||
assert_eq( $body->{sub}, $user->user_id ); | ||
|
||
Future->done(1); | ||
}); | ||
}; | ||
|
||
test "Invalid openid access tokens are rejected", | ||
requires => [ $main::HTTP_CLIENT, $main::HOMESERVER_INFO[0] ], | ||
|
||
check => sub { | ||
my ( $http, $info ) = @_; | ||
|
||
$http->do_request_json( | ||
method => "GET", | ||
uri => $info->client_location . "/_matrix/federation/v1/openid/userinfo", | ||
params => { access_token => "an/invalid/token" }, | ||
)->main::expect_http_401; | ||
}; | ||
|
||
test "Requests to userinfo without access tokens are rejected", | ||
requires => [ $main::HTTP_CLIENT, $main::HOMESERVER_INFO[0] ], | ||
|
||
check => sub { | ||
my ( $http, $info ) = @_; | ||
|
||
$http->do_request_json( | ||
method => "GET", | ||
uri => $info->client_location . "/_matrix/federation/v1/openid/userinfo", | ||
)->main::expect_http_401; | ||
}; |