<commit_before>test "Anonymous user cannot view non-world-readable rooms",
   requires => [ qw( first_api_client ), local_user_preparer() ],

   do => sub {
      my ( $api_client, $user ) = @_;

      my $anonymous_user;
      my $room_id;

      register_anonymous_user( $api_client )->then( sub {
         ( $anonymous_user ) = @_;

         matrix_create_and_join_room( [ $user ] )
         ->then( sub {
            ( $room_id ) = @_;

            do_request_json_for( $user,
               method => "PUT",
               uri    => "/api/v1/rooms/$room_id/state/m.room.history_visibility/",

               content => {
                  history_visibility => "shared",
               },
            );
         })->then( sub {
            matrix_send_room_text_message( $user, $room_id, body => "mice" )
         })->then( sub {
            do_request_json_for( $anonymous_user,
               method => "GET",
               uri => "/api/v1/rooms/${room_id}/messages",
               params => {
                  limit => "1",
                  dir => "b",
               },
            )
         })->followed_by(\&main::expect_http_403);
      });
   };

test "Anonymous user can view world-readable rooms",
   requires => [ qw( first_api_client ), local_user_preparer() ],

   do => sub {
      my ( $api_client, $user ) = @_;

      my $anonymous_user;
      my $room_id;

      register_anonymous_user( $api_client )->then( sub {
         ( $anonymous_user ) = @_;

         matrix_create_and_join_room( [ $user ] )
         ->then( sub {
            ( $room_id ) = @_;

            do_request_json_for( $user,
               method => "PUT",
               uri    => "/api/v1/rooms/$room_id/state/m.room.history_visibility/",

               content => {
                  history_visibility => "world_readable",
               },
            );
         })->then( sub {
            matrix_send_room_text_message( $user, $room_id, body => "mice" )
         })->then( sub {
            do_request_json_for( $anonymous_user,
               method => "GET",
               uri => "/api/v1/rooms/${room_id}/messages",
               params => {
                  limit => "2",
                  dir => "b",
               },
            )
         });
      });
   };

sub register_anonymous_user
{
   my ( $http ) = @_;

   $http->do_request_json(
      method  => "POST",
      uri     => "/v2_alpha/register?kind=guest",
      content => {},
      params => {
         kind => "guest",
      },
   )->then( sub {
      my ( $body ) = @_;
      my $access_token = $body->{access_token};

      Future->done( User( $http, $body->{user_id}, $access_token, undef, undef, [], undef ) );
   });
}
<commit_msg>Remove superfluous querystring<commit_after>test "Anonymous user cannot view non-world-readable rooms",
   requires => [ qw( first_api_client ), local_user_preparer() ],

   do => sub {
      my ( $api_client, $user ) = @_;

      my $anonymous_user;
      my $room_id;

      register_anonymous_user( $api_client )->then( sub {
         ( $anonymous_user ) = @_;

         matrix_create_and_join_room( [ $user ] )
         ->then( sub {
            ( $room_id ) = @_;

            do_request_json_for( $user,
               method => "PUT",
               uri    => "/api/v1/rooms/$room_id/state/m.room.history_visibility/",

               content => {
                  history_visibility => "shared",
               },
            );
         })->then( sub {
            matrix_send_room_text_message( $user, $room_id, body => "mice" )
         })->then( sub {
            do_request_json_for( $anonymous_user,
               method => "GET",
               uri => "/api/v1/rooms/${room_id}/messages",
               params => {
                  limit => "1",
                  dir => "b",
               },
            )
         })->followed_by(\&main::expect_http_403);
      });
   };

test "Anonymous user can view world-readable rooms",
   requires => [ qw( first_api_client ), local_user_preparer() ],

   do => sub {
      my ( $api_client, $user ) = @_;

      my $anonymous_user;
      my $room_id;

      register_anonymous_user( $api_client )->then( sub {
         ( $anonymous_user ) = @_;

         matrix_create_and_join_room( [ $user ] )
         ->then( sub {
            ( $room_id ) = @_;

            do_request_json_for( $user,
               method => "PUT",
               uri    => "/api/v1/rooms/$room_id/state/m.room.history_visibility/",

               content => {
                  history_visibility => "world_readable",
               },
            );
         })->then( sub {
            matrix_send_room_text_message( $user, $room_id, body => "mice" )
         })->then( sub {
            do_request_json_for( $anonymous_user,
               method => "GET",
               uri => "/api/v1/rooms/${room_id}/messages",
               params => {
                  limit => "2",
                  dir => "b",
               },
            )
         });
      });
   };

sub register_anonymous_user
{
   my ( $http ) = @_;

   $http->do_request_json(
      method  => "POST",
      uri     => "/v2_alpha/register",
      content => {},
      params => {
         kind => "guest",
      },
   )->then( sub {
      my ( $body ) = @_;
      my $access_token = $body->{access_token};

      Future->done( User( $http, $body->{user_id}, $access_token, undef, undef, [], undef ) );
   });
}

{'fraction_non_alphanumeric': 0.15220588235294116, 'fraction_numerical': 0.003676470588235294, 'mean_word_length': 1.5108444854637748, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 89, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1990025', 'n_tokens_mistral': 1726, 'n_tokens_neox': 1654, 'n_words': 298}