Skip to content

Commit

Permalink
Test registration idempotency (Tests matrix-org/synapse#649)
Browse files Browse the repository at this point in the history
  • Loading branch information
dbkr committed Mar 16, 2016
1 parent 5f9789a commit 2d709b1
Showing 1 changed file with 73 additions and 0 deletions.
73 changes: 73 additions & 0 deletions tests/11register.pl
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,76 @@
}),
)
};

test "registration is idempotent",
requires => [ $main::API_CLIENTS[0] ],

do => sub {
my ( $http ) = @_;

my $session;
my $user_id;

# Start a session
$http->do_request_json(
method => "POST",
uri => "/r0/register",

content => {
password => "s3kr1t",
},
)->main::expect_http_401->then( sub {
my ( $response ) = @_;

my $body = decode_json $response->content;

assert_json_keys( $body, qw( session ));

$session = $body->{session};

# Now register a user
$http->do_request_json(
method => "POST",
uri => "/r0/register",

content => {
password => "s3kr1t",
auth => {
session => $session,
type => "m.login.dummy",
}
},
);
})->then( sub {
my ( $body ) = @_;

# check that worked okay...
assert_json_keys( $body, qw( user_id home_server access_token refresh_token ));

$user_id = $body->{user_id};

# now try to register again with the same session
$http->do_request_json(
method => "POST",
uri => "/r0/register",

content => {
password => "s3kr1t",
auth => {
session => $session,
type => "m.login.dummy",
}
},
);
})->then( sub {
my ( $body ) = @_;

# we should have got an equivalent response
# (ie. success, and the same user id)
assert_json_keys( $body, qw( user_id home_server access_token refresh_token ));

assert_eq( $body->{user_id}, $user_id );

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

0 comments on commit 2d709b1

Please sign in to comment.