Skip to content

Commit

Permalink
Add support for handling email validation challenges
Browse files Browse the repository at this point in the history
As of MSC2078, the homeserver is allowed to send its own email validation when
we do a /requestToken, so stubbing it out in the test Identity Server no longer
cuts the mustard.
  • Loading branch information
richvdh committed Sep 18, 2019
1 parent 476476e commit ac71f13
Showing 1 changed file with 39 additions and 3 deletions.
42 changes: 39 additions & 3 deletions tests/12login/01threepid-and-password.pl
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,53 @@ sub validate_email_for_user {
Future->done;
}),

# we now expect a callout to our test ID server.
await_id_validation( $id_server, $address ),
# depending on the server under test, we should expect either a callout to
# our test ID server, or an email from the homeserver.
#
Future->wait_any(
await_and_confirm_email( $address, $user->http ),
await_id_validation( $id_server, $address ),
),
)->then( sub {
Future->done( $sid, $client_secret );
});
}

push our @EXPORT, qw( validate_email_for_user );

# wait for a call to /requestToken on the test IS, and act as if the
# email has been validated.
sub await_and_confirm_email {
my ( $address, $http ) = @_;

my $confirm_uri;

return await_email_to( $address )->then( sub {
my ( $from, $email ) = @_;
log_if_fail "got email from $from";

$email->walk_parts( sub {
my ( $part ) = @_;
return if $part->subparts; # multipart
if ( $part->content_type =~ m[text/plain]i ) {
my $body = $part->body;
log_if_fail "got email body", $body;

unless( $body =~ /(http\S*)/ ) {
die "confirmation URI not found in email body";
}

$confirm_uri = $1;
}
});

# do an http hit on the confirmation url
$http->do_request(
method => "GET",
full_uri => $confirm_uri,
);
});
}

sub await_id_validation {
my ( $id_server, $address ) = @_;

Expand Down

0 comments on commit ac71f13

Please sign in to comment.