Skip to content

Commit

Permalink
Make 3PID binding tests use /account/3pid/bind ala MSC2290 (#703)
Browse files Browse the repository at this point in the history
Synapse PR: matrix-org/synapse#6043

Changes the 3PID binding tests to use the new unstable /account/3pid/bind API endpoint, defined in MSC2290.
  • Loading branch information
anoadragon453 authored and richvdh committed Sep 23, 2019
1 parent cf86485 commit 626ce88
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 24 deletions.
14 changes: 0 additions & 14 deletions tests/12login/01threepid-and-password.pl
Original file line number Diff line number Diff line change
Expand Up @@ -120,24 +120,11 @@ =head2 add_email_for_user
Add the given email address to the homeserver account, including the
verfication steps.
C<%params> may include:
=over
=item bind => SCALAR
If truthy, we will ask the server to ask the IS to bind the email
address. False by default.
=back
=cut

sub add_email_for_user {
my ( $user, $address, $id_server, %params ) = @_;

my $bind = $params{bind} // 0;

my $id_access_token = $id_server->get_access_token();

# start by requesting an email validation.
Expand All @@ -157,7 +144,6 @@ sub add_email_for_user {
sid => $sid,
client_secret => $client_secret,
},
bind => $bind ? JSON::true : JSON::false,
},
);
});
Expand Down
43 changes: 33 additions & 10 deletions tests/54identity.pl
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
sub bind_email_for_user {
my ( $user, $address, $id_server, %params ) = @_;

my $client_secret = join "", map { chr 40 + rand 86 } 1 .. 20;

my $id_access_token = $id_server->get_access_token();

my $sid = $id_server->validate_identity( 'email', $address, $client_secret );

do_request_json_for(
$user,
method => "POST",
uri => "/unstable/account/3pid/bind",
content => {
id_server => $id_server->name,
id_access_token => $id_access_token,
sid => $sid,
client_secret => $client_secret,
},
);
}


test "Can bind 3PID via home server",
requires => [ $main::HTTP_CLIENT, local_user_fixture(), id_server_fixture() ],

Expand All @@ -7,8 +30,8 @@
my $medium = "email";
my $address = '[email protected]';

add_email_for_user(
$user, $address, $id_server, bind => 1,
bind_email_for_user(
$user, $address, $id_server,
)->then( sub {
my $res = $id_server->lookup_identity( $medium, $address );

Expand All @@ -28,8 +51,8 @@
my $medium = "email";
my $address = '[email protected]';

add_email_for_user(
$user, $address, $id_server, bind => 1,
bind_email_for_user(
$user, $address, $id_server,
)->then( sub {
my $res = $id_server->lookup_identity( $medium, $address );
assert_eq( $res, $user->user_id );
Expand Down Expand Up @@ -91,8 +114,8 @@
my $medium = "email";
my $address = '[email protected]';

add_email_for_user(
$user, $address, $id_server, bind => 1,
bind_email_for_user(
$user, $address, $id_server,
)->then( sub {
my $res = $id_server->lookup_identity( $medium, $address );
assert_eq( $res, $user->user_id );
Expand All @@ -116,8 +139,8 @@
my $medium = "email";
my $address = '[email protected]';

add_email_for_user(
$user, $address, $id_server, bind => 1,
bind_email_for_user(
$user, $address, $id_server,
)->then( sub {
my $res = $id_server->lookup_identity( $medium, $address );
assert_eq( $res, $user->user_id );
Expand Down Expand Up @@ -149,8 +172,8 @@
my $medium = "email";
my $address = '[email protected]';

add_email_for_user(
$user, $address, $id_server, bind => 1,
bind_email_for_user(
$user, $address, $id_server,
)->then( sub {
my $res = $id_server->lookup_identity( $medium, $address );
assert_eq( $res, $user->user_id );
Expand Down

0 comments on commit 626ce88

Please sign in to comment.