Skip to content

Commit

Permalink
Add tests for 3PID /unbind API
Browse files Browse the repository at this point in the history
  • Loading branch information
anoadragon453 committed Sep 5, 2019
1 parent 34f5792 commit 156dd29
Showing 1 changed file with 89 additions and 0 deletions.
89 changes: 89 additions & 0 deletions tests/54identity.pl
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,92 @@
Future->done( 1 );
});
};


test "Can bind and unbind 3PID via /unbind by specifying the identity server",
requires => [ $main::HTTP_CLIENT, local_user_fixture(), id_server_fixture() ],

check => sub {
my ( $http, $user, $id_server ) = @_;

my $medium = "email";
my $address = 'bobby@example.com';
my $client_secret = "53kr3t";

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

do_request_json_for( $user,
method => "POST",
uri => "/r0/account/3pid",
content => {
three_pid_creds => {
id_server => $id_server->name,
sid => $sid,
client_secret => $client_secret,
},
bind => JSON::true,
},
)->then( sub {
my $res = $id_server->lookup_identity( $medium, $address );
assert_eq( $res, $user->user_id );

do_request_json_for( $user,
method => "POST",
uri => "/r0/account/3pid/unbind",
content => {
id_server => $id_server->name,
medium => $medium,
address => $address,
},
)
})->then( sub {
my $res = $id_server->lookup_identity( $medium, $address );
!defined $res or die "User 3PID still bound";

Future->done( 1 );
});
};


test "Can bind and unbind 3PID via /unbind without specifying the identity server",
requires => [ $main::HTTP_CLIENT, local_user_fixture(), id_server_fixture() ],

check => sub {
my ( $http, $user, $id_server ) = @_;

my $medium = "email";
my $address = 'bobby@example.com';
my $client_secret = "53kr3t";

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

do_request_json_for( $user,
method => "POST",
uri => "/r0/account/3pid",
content => {
three_pid_creds => {
id_server => $id_server->name,
sid => $sid,
client_secret => $client_secret,
},
bind => JSON::true,
},
)->then( sub {
my $res = $id_server->lookup_identity( $medium, $address );
assert_eq( $res, $user->user_id );

do_request_json_for( $user,
method => "POST",
uri => "/r0/account/3pid/unbind",
content => {
medium => $medium,
address => $address,
},
)
})->then( sub {
my $res = $id_server->lookup_identity( $medium, $address );
!defined $res or die "User 3PID still bound";

Future->done( 1 );
});
};

0 comments on commit 156dd29

Please sign in to comment.