Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make 3PID binding tests use /account/3pid/bind ala MSC2290 #703

Merged
merged 6 commits into from
Sep 23, 2019
Merged
Show file tree
Hide file tree
Changes from 5 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
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 {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If bind_email_for_user is using the new bind API, should this method use the new add API?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess... we can do that later though?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True

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 = 'bob1@example.com';

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 = 'bob2@example.com';

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 = 'bob4@example.com';

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 = 'bobby@example.com';

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 = 'bobby2@example.com';

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