From 91e7ec61ca2a254199da44bdc315bcc95a90cd27 Mon Sep 17 00:00:00 2001 From: "Paul \"LeoNerd\" Evans" Date: Tue, 22 Dec 2015 17:30:24 +0000 Subject: [PATCH 1/5] Add room_alias_name_fixture() for dynamically allocating new room alias name localparts --- tests/10apidoc/30room-create.pl | 28 ++++++++++++++++++++++++++++ tests/10apidoc/31room-state.pl | 6 +++--- tests/10apidoc/33room-members.pl | 6 +++--- tests/30rooms/03members-remote.pl | 12 ++++++------ tests/30rooms/05aliases.pl | 6 +++--- 5 files changed, 43 insertions(+), 15 deletions(-) diff --git a/tests/10apidoc/30room-create.pl b/tests/10apidoc/30room-create.pl index 0b69828f5..ebec7060f 100644 --- a/tests/10apidoc/30room-create.pl +++ b/tests/10apidoc/30room-create.pl @@ -122,3 +122,31 @@ sub matrix_create_room Future->done( $body->{room_id}, $body->{room_alias} ); }); } + +push @EXPORT, qw( room_alias_name_fixture ); + +my $next_alias_name = 0; + +=head2 room_alias_name_fixture + + $fixture = room_alias_name_fixture + +Returns a new Fixture, which when provisioned will allocate a new room alias +name (i.e. localpart, before the homeserver domain name, and return it as a +string. + +=cut + +sub room_alias_name_fixture +{ + return fixture( + setup => sub { + my ( $info ) = @_; + + my $alias_name = sprintf "__ANON__-%d", $next_alias_name++; + + Future->done( $alias_name ); + }, + ); +} + diff --git a/tests/10apidoc/31room-state.pl b/tests/10apidoc/31room-state.pl index c27a267d5..4cef4df27 100644 --- a/tests/10apidoc/31room-state.pl +++ b/tests/10apidoc/31room-state.pl @@ -6,13 +6,13 @@ # This provides $room_id *AND* $room_alias my $room_fixture = fixture( - requires => [ $user_fixture ], + requires => [ $user_fixture, room_alias_name_fixture() ], setup => sub { - my ( $user ) = @_; + my ( $user, $room_alias_name ) = @_; matrix_create_room( $user, - room_alias_name => "31room-state", + room_alias_name => $room_alias_name, ); }, ); diff --git a/tests/10apidoc/33room-members.pl b/tests/10apidoc/33room-members.pl index 65616f523..dc72ba48c 100644 --- a/tests/10apidoc/33room-members.pl +++ b/tests/10apidoc/33room-members.pl @@ -6,13 +6,13 @@ # This provides $room_id *AND* $room_alias my $room_fixture = fixture( - requires => [ $creator_fixture ], + requires => [ $creator_fixture, room_alias_name_fixture() ], setup => sub { - my ( $user ) = @_; + my ( $user, $room_alias_name ) = @_; matrix_create_room( $user, - room_alias_name => "33room-members", + room_alias_name => $room_alias_name, ); }, ); diff --git a/tests/30rooms/03members-remote.pl b/tests/30rooms/03members-remote.pl index d19f1ba5d..7e05d54a6 100644 --- a/tests/30rooms/03members-remote.pl +++ b/tests/30rooms/03members-remote.pl @@ -11,13 +11,13 @@ my $remote_user_fixture = remote_user_fixture(); my $room_fixture = fixture( - requires => [ $creator_fixture ], + requires => [ $creator_fixture, room_alias_name_fixture() ], setup => sub { - my ( $user ) = @_; + my ( $user, $room_alias_name ) = @_; matrix_create_room( $user, - room_alias_name => "03members-remote" + room_alias_name => $room_alias_name, ); }, ); @@ -208,14 +208,14 @@ }; test "Remote users may not join unfederated rooms", - requires => [ local_user_fixture(), remote_user_fixture(), + requires => [ local_user_fixture(), remote_user_fixture(), room_alias_name_fixture(), qw( can_create_room_with_creation_content )], check => sub { - my ( $creator, $remote_user ) = @_; + my ( $creator, $remote_user, $room_alias_name ) = @_; matrix_create_room( $creator, - room_alias_name => "unfederated", + room_alias_name => $room_alias_name, creation_content => { "m.federate" => JSON::false, }, diff --git a/tests/30rooms/05aliases.pl b/tests/30rooms/05aliases.pl index ccf0c6850..ebf9ea284 100644 --- a/tests/30rooms/05aliases.pl +++ b/tests/30rooms/05aliases.pl @@ -71,15 +71,15 @@ }; multi_test "Canonical alias can be set", - requires => [ local_user_fixture() ], + requires => [ local_user_fixture(), room_alias_name_fixture() ], do => sub { - my ( $user ) = @_; + my ( $user, $room_alias_name ) = @_; my ( $room_id, $room_alias ); matrix_create_room( $user, - room_alias_name => "is-this-canonical", + room_alias_name => $room_alias_name, )->then( sub { ( $room_id, $room_alias ) = @_; From 693f35075c12bd62b821f12fbfa76e924326bd52 Mon Sep 17 00:00:00 2001 From: "Paul \"LeoNerd\" Evans" Date: Tue, 22 Dec 2015 18:13:50 +0000 Subject: [PATCH 2/5] Use room_alias_name_fixture() in a couple more places --- tests/10apidoc/32room-alias.pl | 17 +++++++++-------- tests/50federation/11query-directory.pl | 7 ++++--- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/tests/10apidoc/32room-alias.pl b/tests/10apidoc/32room-alias.pl index 1926b9939..90ea57137 100644 --- a/tests/10apidoc/32room-alias.pl +++ b/tests/10apidoc/32room-alias.pl @@ -1,5 +1,3 @@ -my $alias_localpart = "#another-alias"; - my $user_fixture = local_user_fixture(); my $room_fixture = fixture( @@ -8,19 +6,22 @@ setup => sub { my ( $user ) = @_; - matrix_create_room( $user ); + matrix_create_room( $user )->then( sub { + my ( $room_id, undef ) = @_; + Future->done( $room_id ); # Don't return the alias + }); }, ); test "PUT /directory/room/:room_alias creates alias", - requires => [ $user_fixture, $room_fixture ], + requires => [ $user_fixture, $room_fixture, room_alias_name_fixture() ], proves => [qw( can_create_room_alias can_lookup_room_alias )], do => sub { - my ( $user, $room_id ) = @_; + my ( $user, $room_id, $room_alias_name ) = @_; my $server_name = $user->http->server_name; - my $room_alias = "${alias_localpart}:$server_name"; + my $room_alias = "#${room_alias_name}:$server_name"; do_request_json_for( $user, method => "PUT", @@ -33,9 +34,9 @@ }, check => sub { - my ( $user, $room_id ) = @_; + my ( $user, $room_id, $room_alias_name ) = @_; my $server_name = $user->http->server_name; - my $room_alias = "${alias_localpart}:$server_name"; + my $room_alias = "#${room_alias_name}:$server_name"; do_request_json_for( $user, method => "GET", diff --git a/tests/50federation/11query-directory.pl b/tests/50federation/11query-directory.pl index 87f75fb3d..54e3ee403 100644 --- a/tests/50federation/11query-directory.pl +++ b/tests/50federation/11query-directory.pl @@ -44,15 +44,16 @@ # TODO(paul): technically this doesn't need local_user_fixture(), if we had # some user we could assert can perform media/directory/etc... operations # but doesn't mutate any of its own state, or join rooms, etc... - requires => [ $main::OUTBOUND_CLIENT, $main::HOMESERVER_INFO[0], local_user_fixture(), + requires => [ $main::OUTBOUND_CLIENT, $main::HOMESERVER_INFO[0], + local_user_fixture(), room_alias_name_fixture(), qw( can_create_room_alias )], do => sub { - my ( $outbound_client, $info, $user ) = @_; + my ( $outbound_client, $info, $user, $room_alias_name ) = @_; my $first_home_server = $info->server_name; my $room_id; - my $room_alias = "#50federation-11query-directory:$first_home_server"; + my $room_alias = "#${room_alias_name}:$first_home_server"; matrix_create_room( $user ) ->then( sub { From a50526b52cdeccf2b1e90c09082d9c438fda3c38 Mon Sep 17 00:00:00 2001 From: "Paul \"LeoNerd\" Evans" Date: Tue, 22 Dec 2015 19:04:52 +0000 Subject: [PATCH 3/5] Also generate AS test room aliases using room_alias_name_fixture() --- tests/10apidoc/30room-create.pl | 11 +++++++++-- tests/60app-services/01as-create.pl | 22 ++++++++++++++-------- tests/60app-services/03passive.pl | 5 +++-- 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/tests/10apidoc/30room-create.pl b/tests/10apidoc/30room-create.pl index ebec7060f..0bccabeec 100644 --- a/tests/10apidoc/30room-create.pl +++ b/tests/10apidoc/30room-create.pl @@ -129,21 +129,28 @@ sub matrix_create_room =head2 room_alias_name_fixture - $fixture = room_alias_name_fixture + $fixture = room_alias_name_fixture( prefix => $prefix ) Returns a new Fixture, which when provisioned will allocate a new room alias name (i.e. localpart, before the homeserver domain name, and return it as a string. +An optional prefix string can be provided, which will be prepended onto the +alias name. + =cut sub room_alias_name_fixture { + my %args = @_; + + my $prefix = $args{prefix} // ""; + return fixture( setup => sub { my ( $info ) = @_; - my $alias_name = sprintf "__ANON__-%d", $next_alias_name++; + my $alias_name = sprintf "%s__ANON__-%d", $prefix, $next_alias_name++; Future->done( $alias_name ); }, diff --git a/tests/60app-services/01as-create.pl b/tests/60app-services/01as-create.pl index c06fc6aec..7ae8c235c 100644 --- a/tests/60app-services/01as-create.pl +++ b/tests/60app-services/01as-create.pl @@ -57,13 +57,17 @@ }; test "AS can make room aliases", - requires => [ $main::AS_USER, $main::AS_USER_INFO, $room_fixture, - qw( can_create_room_alias )], + requires => [ + $main::AS_USER, $main::AS_USER_INFO, $room_fixture, + room_alias_name_fixture( prefix => "astest-" ), + qw( can_create_room_alias ), + ], do => sub { - my ( $as_user, $as_user_info, $room_id ) = @_; + my ( $as_user, $as_user_info, $room_id, + $room_alias_name ) = @_; my $server_name = $as_user->http->server_name; - my $room_alias = "#astest-01create-1:$server_name"; + my $room_alias = "#${room_alias_name}:$server_name"; Future->needs_all( await_as_event( "m.room.aliases" )->then( sub { @@ -127,13 +131,15 @@ }; test "Regular users cannot create room aliases within the AS namespace", - requires => [ $user_fixture, $room_fixture, - qw( can_create_room_alias )], + requires => [ + $user_fixture, $room_fixture, room_alias_name_fixture( prefix => "astest-" ), + qw( can_create_room_alias ), + ], do => sub { - my ( $user, $room_id ) = @_; + my ( $user, $room_id, $room_alias_name ) = @_; my $server_name = $user->http->server_name; - my $room_alias = "#astest-01create-2:$server_name"; + my $room_alias = "#${room_alias_name}:$server_name"; do_request_json_for( $user, method => "PUT", diff --git a/tests/60app-services/03passive.pl b/tests/60app-services/03passive.pl index 248959822..6661f643b 100644 --- a/tests/60app-services/03passive.pl +++ b/tests/60app-services/03passive.pl @@ -46,14 +46,15 @@ multi_test "Accesing an AS-hosted room alias asks the AS server", requires => [ $main::AS_USER, local_user_fixture(), $room_fixture, + room_alias_name_fixture( prefix => "astest-" ), qw( can_join_room_by_alias )], do => sub { - my ( $as_user, $local_user, $room_id ) = @_; + my ( $as_user, $local_user, $room_id, $room_alias_name ) = @_; my $server_name = $as_user->http->server_name; - my $room_alias = "#astest-03passive-1:$server_name"; + my $room_alias = "#${room_alias_name}:$server_name"; require_stub await_http_request( "/appserv/rooms/$room_alias", sub { 1 } ) ->then( sub { From 63ea898fb36c5a7315739d8d9e22108492f54de2 Mon Sep 17 00:00:00 2001 From: "Paul \"LeoNerd\" Evans" Date: Mon, 4 Jan 2016 14:31:08 +0000 Subject: [PATCH 4/5] Added 'room_alias_fixture()' --- tests/10apidoc/30room-create.pl | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/tests/10apidoc/30room-create.pl b/tests/10apidoc/30room-create.pl index 0bccabeec..f43e87217 100644 --- a/tests/10apidoc/30room-create.pl +++ b/tests/10apidoc/30room-create.pl @@ -123,7 +123,7 @@ sub matrix_create_room }); } -push @EXPORT, qw( room_alias_name_fixture ); +push @EXPORT, qw( room_alias_name_fixture room_alias_fixture ); my $next_alias_name = 0; @@ -157,3 +157,33 @@ sub room_alias_name_fixture ); } +=head2 room_alias_fixture + + $fixture = room_alias_fixture( prefix => $prefix ) + +Returns a new Fixture, which when provisioned will allocate a name for a new +room alias on the first homeserver, and return it as a string. Note that this +does not actually create the alias on the server itself, it simply suggests a +new unique name for one. + +An optional prefix string can be provided, which will be prepended onto the +alias name. + +=cut + +sub room_alias_fixture +{ + my %args = @_; + + return fixture( + requires => [ + room_alias_name_fixture( prefix => $args{prefix} ), $main::HOMESERVER_INFO[0], + ], + + setup => sub { + my ( $alias_name, $info ) = @_; + + Future->done( sprintf "#%s:%s", $alias_name, $info->server_name ); + }, + ); +} From 1642c8373214f74d975af5aee26e196cbd466a07 Mon Sep 17 00:00:00 2001 From: "Paul \"LeoNerd\" Evans" Date: Mon, 4 Jan 2016 14:31:34 +0000 Subject: [PATCH 5/5] Use 'room_alias_fixture()' where possible instead of room_alias_name_fixture() with separate domain name appending --- tests/10apidoc/32room-alias.pl | 10 +++------- tests/50federation/11query-directory.pl | 5 ++--- tests/60app-services/01as-create.pl | 13 ++++--------- tests/60app-services/03passive.pl | 7 ++----- 4 files changed, 11 insertions(+), 24 deletions(-) diff --git a/tests/10apidoc/32room-alias.pl b/tests/10apidoc/32room-alias.pl index 90ea57137..bb7e353d8 100644 --- a/tests/10apidoc/32room-alias.pl +++ b/tests/10apidoc/32room-alias.pl @@ -14,14 +14,12 @@ ); test "PUT /directory/room/:room_alias creates alias", - requires => [ $user_fixture, $room_fixture, room_alias_name_fixture() ], + requires => [ $user_fixture, $room_fixture, room_alias_fixture() ], proves => [qw( can_create_room_alias can_lookup_room_alias )], do => sub { - my ( $user, $room_id, $room_alias_name ) = @_; - my $server_name = $user->http->server_name; - my $room_alias = "#${room_alias_name}:$server_name"; + my ( $user, $room_id, $room_alias ) = @_; do_request_json_for( $user, method => "PUT", @@ -34,9 +32,7 @@ }, check => sub { - my ( $user, $room_id, $room_alias_name ) = @_; - my $server_name = $user->http->server_name; - my $room_alias = "#${room_alias_name}:$server_name"; + my ( $user, $room_id, $room_alias ) = @_; do_request_json_for( $user, method => "GET", diff --git a/tests/50federation/11query-directory.pl b/tests/50federation/11query-directory.pl index 54e3ee403..fab11e66a 100644 --- a/tests/50federation/11query-directory.pl +++ b/tests/50federation/11query-directory.pl @@ -45,15 +45,14 @@ # some user we could assert can perform media/directory/etc... operations # but doesn't mutate any of its own state, or join rooms, etc... requires => [ $main::OUTBOUND_CLIENT, $main::HOMESERVER_INFO[0], - local_user_fixture(), room_alias_name_fixture(), + local_user_fixture(), room_alias_fixture(), qw( can_create_room_alias )], do => sub { - my ( $outbound_client, $info, $user, $room_alias_name ) = @_; + my ( $outbound_client, $info, $user, $room_alias ) = @_; my $first_home_server = $info->server_name; my $room_id; - my $room_alias = "#${room_alias_name}:$first_home_server"; matrix_create_room( $user ) ->then( sub { diff --git a/tests/60app-services/01as-create.pl b/tests/60app-services/01as-create.pl index 7ae8c235c..c10918127 100644 --- a/tests/60app-services/01as-create.pl +++ b/tests/60app-services/01as-create.pl @@ -59,15 +59,12 @@ test "AS can make room aliases", requires => [ $main::AS_USER, $main::AS_USER_INFO, $room_fixture, - room_alias_name_fixture( prefix => "astest-" ), + room_alias_fixture( prefix => "astest-" ), qw( can_create_room_alias ), ], do => sub { - my ( $as_user, $as_user_info, $room_id, - $room_alias_name ) = @_; - my $server_name = $as_user->http->server_name; - my $room_alias = "#${room_alias_name}:$server_name"; + my ( $as_user, $as_user_info, $room_id, $room_alias ) = @_; Future->needs_all( await_as_event( "m.room.aliases" )->then( sub { @@ -132,14 +129,12 @@ test "Regular users cannot create room aliases within the AS namespace", requires => [ - $user_fixture, $room_fixture, room_alias_name_fixture( prefix => "astest-" ), + $user_fixture, $room_fixture, room_alias_fixture( prefix => "astest-" ), qw( can_create_room_alias ), ], do => sub { - my ( $user, $room_id, $room_alias_name ) = @_; - my $server_name = $user->http->server_name; - my $room_alias = "#${room_alias_name}:$server_name"; + my ( $user, $room_id, $room_alias ) = @_; do_request_json_for( $user, method => "PUT", diff --git a/tests/60app-services/03passive.pl b/tests/60app-services/03passive.pl index 6661f643b..4e72419db 100644 --- a/tests/60app-services/03passive.pl +++ b/tests/60app-services/03passive.pl @@ -46,15 +46,12 @@ multi_test "Accesing an AS-hosted room alias asks the AS server", requires => [ $main::AS_USER, local_user_fixture(), $room_fixture, - room_alias_name_fixture( prefix => "astest-" ), + room_alias_fixture( prefix => "astest-" ), qw( can_join_room_by_alias )], do => sub { - my ( $as_user, $local_user, $room_id, $room_alias_name ) = @_; - my $server_name = $as_user->http->server_name; - - my $room_alias = "#${room_alias_name}:$server_name"; + my ( $as_user, $local_user, $room_id, $room_alias ) = @_; require_stub await_http_request( "/appserv/rooms/$room_alias", sub { 1 } ) ->then( sub {