@Test public void saveAuthorizedClientWhenAuthorizedClientIsNullThenThrowIllegalArgumentException() { assertThatThrownBy(() -> this.authorizedClientRepository.saveAuthorizedClient(null, null, this.exchange).block()) .isInstanceOf(IllegalArgumentException.class); }
@Test public void saveAuthorizedClientWhenRequestIsNullThenThrowIllegalArgumentException() { OAuth2AuthorizedClient authorizedClient = new OAuth2AuthorizedClient( this.registration2, this.principalName1, mock(OAuth2AccessToken.class)); assertThatThrownBy(() -> this.authorizedClientRepository.saveAuthorizedClient(authorizedClient, null, null).block()) .isInstanceOf(IllegalArgumentException.class); }
@Test public void saveAuthorizedClientWhenAuthenticationIsNullThenExceptionNotThrown() { OAuth2AuthorizedClient authorizedClient = new OAuth2AuthorizedClient( this.registration2, this.principalName1, mock(OAuth2AccessToken.class)); this.authorizedClientRepository.saveAuthorizedClient(authorizedClient, null, this.exchange).block(); }
@Test public void loadAuthorizedClientWhenSavedThenReturnAuthorizedClient() { OAuth2AuthorizedClient authorizedClient = new OAuth2AuthorizedClient( this.registration1, this.principalName1, mock(OAuth2AccessToken.class)); this.authorizedClientRepository.saveAuthorizedClient(authorizedClient, null, this.exchange).block(); OAuth2AuthorizedClient loadedAuthorizedClient = this.authorizedClientRepository.loadAuthorizedClient(this.registrationId1, null, this.exchange).block(); assertThat(loadedAuthorizedClient).isEqualTo(authorizedClient); }
@Test public void saveAuthorizedClientWhenSavedThenSavedToSession() { OAuth2AuthorizedClient expected = new OAuth2AuthorizedClient( this.registration2, this.principalName1, mock(OAuth2AccessToken.class)); this.authorizedClientRepository.saveAuthorizedClient(expected, null, this.exchange).block(); OAuth2AuthorizedClient result = this.authorizedClientRepository .loadAuthorizedClient(this.registrationId2, null, this.exchange).block(); assertThat(result).isEqualTo(expected); }
@Test public void removeAuthorizedClientWhenClient1Client2SavedAndClient1RemovedThenClient2NotRemoved() { OAuth2AuthorizedClient authorizedClient1 = new OAuth2AuthorizedClient( this.registration1, this.principalName1, mock(OAuth2AccessToken.class)); this.authorizedClientRepository.saveAuthorizedClient(authorizedClient1, null, this.exchange).block(); OAuth2AuthorizedClient authorizedClient2 = new OAuth2AuthorizedClient( this.registration2, this.principalName1, mock(OAuth2AccessToken.class)); this.authorizedClientRepository.saveAuthorizedClient(authorizedClient2, null, this.exchange).block(); this.authorizedClientRepository.removeAuthorizedClient( this.registrationId1, null, this.exchange).block(); OAuth2AuthorizedClient loadedAuthorizedClient2 = this.authorizedClientRepository.loadAuthorizedClient( this.registrationId2, null, this.exchange).block(); assertThat(loadedAuthorizedClient2).isNotNull(); assertThat(loadedAuthorizedClient2).isSameAs(authorizedClient2); } }
@Test public void removeAuthorizedClientWhenClient1SavedAndClient2RemovedThenClient1NotRemoved() { OAuth2AuthorizedClient authorizedClient1 = new OAuth2AuthorizedClient( this.registration1, this.principalName1, mock(OAuth2AccessToken.class)); this.authorizedClientRepository.saveAuthorizedClient(authorizedClient1, null, this.exchange).block(); // Remove registrationId2 (never added so is not removed either) this.authorizedClientRepository.removeAuthorizedClient( this.registrationId2, null, this.exchange); OAuth2AuthorizedClient loadedAuthorizedClient1 = this.authorizedClientRepository.loadAuthorizedClient( this.registrationId1, null, this.exchange).block(); assertThat(loadedAuthorizedClient1).isNotNull(); assertThat(loadedAuthorizedClient1).isSameAs(authorizedClient1); }
@Test public void removeAuthorizedClientWhenSavedThenRemovedFromSession() { OAuth2AuthorizedClient authorizedClient = new OAuth2AuthorizedClient( this.registration1, this.principalName1, mock(OAuth2AccessToken.class)); this.authorizedClientRepository.saveAuthorizedClient(authorizedClient, null, this.exchange).block(); OAuth2AuthorizedClient loadedAuthorizedClient = this.authorizedClientRepository.loadAuthorizedClient( this.registrationId1, null, this.exchange).block(); assertThat(loadedAuthorizedClient).isSameAs(authorizedClient); this.authorizedClientRepository.removeAuthorizedClient( this.registrationId1, null, this.exchange).block(); WebSession session = this.exchange.getSession().block(); assertThat(session).isNotNull(); assertThat(session.getAttributes()).isEmpty(); }
@Test public void removeAuthorizedClientWhenSavedThenRemoved() { OAuth2AuthorizedClient authorizedClient = new OAuth2AuthorizedClient( this.registration2, this.principalName1, mock(OAuth2AccessToken.class)); this.authorizedClientRepository.saveAuthorizedClient(authorizedClient, null, this.exchange).block(); OAuth2AuthorizedClient loadedAuthorizedClient = this.authorizedClientRepository.loadAuthorizedClient( this.registrationId2, null, this.exchange).block(); assertThat(loadedAuthorizedClient).isSameAs(authorizedClient); this.authorizedClientRepository.removeAuthorizedClient( this.registrationId2, null, this.exchange).block(); loadedAuthorizedClient = this.authorizedClientRepository.loadAuthorizedClient( this.registrationId2, null, this.exchange).block(); assertThat(loadedAuthorizedClient).isNull(); }