@Test public void matchesWhenPrefixInMiddleThenFalse() { assertThatThrownBy(() -> this.passwordEncoder.matches(this.rawPassword, "invalid" + this.bcryptEncodedPassword)) .isInstanceOf(IllegalArgumentException.class) .hasMessage("There is no PasswordEncoder mapped for the id \"null\""); verifyZeroInteractions(this.bcrypt, this.noop); }
@Test(expected = IllegalArgumentException.class) public void matchesWhenRawPasswordNotNullAndEncodedPasswordNullThenThrowsIllegalArgumentException() { this.passwordEncoder.matches(this.rawPassword, null); }
@Test public void matchesWhenNoStartingPrefixStringThenFalse() { assertThatThrownBy(() -> this.passwordEncoder.matches(this.rawPassword, "bcrypt}" + this.rawPassword)) .isInstanceOf(IllegalArgumentException.class) .hasMessage("There is no PasswordEncoder mapped for the id \"null\""); verifyZeroInteractions(this.bcrypt, this.noop); }
@Test public void matchesWhenNoIdStringThenFalse() { assertThatThrownBy(() -> this.passwordEncoder.matches(this.rawPassword, "{}" + this.rawPassword)) .isInstanceOf(IllegalArgumentException.class) .hasMessage("There is no PasswordEncoder mapped for the id \"\""); verifyZeroInteractions(this.bcrypt, this.noop); }
@Test public void matchesWhenUnMappedThenIllegalArgumentException() { assertThatThrownBy(() -> this.passwordEncoder.matches(this.rawPassword, "{unmapped}" + this.rawPassword)) .isInstanceOf(IllegalArgumentException.class) .hasMessage("There is no PasswordEncoder mapped for the id \"unmapped\""); verifyZeroInteractions(this.bcrypt, this.noop); }
@Test public void matchesWhenNoClosingPrefixStringThenIllegalArgumentExcetion() { assertThatThrownBy(() -> this.passwordEncoder.matches(this.rawPassword, "{bcrypt" + this.rawPassword)) .isInstanceOf(IllegalArgumentException.class) .hasMessage("There is no PasswordEncoder mapped for the id \"null\""); verifyZeroInteractions(this.bcrypt, this.noop); }
@Test public void matchesWhenIdIsNullThenFalse() { this.delegates = new Hashtable<>(this.delegates); DelegatingPasswordEncoder passwordEncoder = new DelegatingPasswordEncoder(this.bcryptId, this.delegates); assertThatThrownBy(() -> passwordEncoder.matches(this.rawPassword, this.rawPassword)) .isInstanceOf(IllegalArgumentException.class) .hasMessage("There is no PasswordEncoder mapped for the id \"null\""); verifyZeroInteractions(this.bcrypt, this.noop); }
@Test public void matchesWhenBCryptThenDelegatesToBCrypt() { when(this.bcrypt.matches(this.rawPassword, this.encodedPassword)).thenReturn(true); assertThat(this.passwordEncoder.matches(this.rawPassword, this.bcryptEncodedPassword)).isTrue(); verify(this.bcrypt).matches(this.rawPassword, this.encodedPassword); verifyZeroInteractions(this.noop); }
@Test public void matchesWhenNoopThenDelegatesToNoop() { when(this.noop.matches(this.rawPassword, this.encodedPassword)).thenReturn(true); assertThat(this.passwordEncoder.matches(this.rawPassword, this.noopEncodedPassword)).isTrue(); verify(this.noop).matches(this.rawPassword, this.encodedPassword); verifyZeroInteractions(this.bcrypt); }
@Test public void matchesWhenNullIdThenDelegatesToInvalidId() { this.delegates.put(null, this.invalidId); this.passwordEncoder = new DelegatingPasswordEncoder(this.bcryptId, this.delegates); when(this.invalidId.matches(this.rawPassword, this.encodedPassword)).thenReturn(true); assertThat(this.passwordEncoder.matches(this.rawPassword, this.encodedPassword)).isTrue(); verify(this.invalidId).matches(this.rawPassword, this.encodedPassword); verifyZeroInteractions(this.bcrypt, this.noop); }
@Test public void matchesWhenCustomDefaultPasswordEncoderForMatchesThenDelegates() { String encodedPassword = "{unmapped}" + this.rawPassword; this.passwordEncoder.setDefaultPasswordEncoderForMatches(this.invalidId); assertThat(this.passwordEncoder.matches(this.rawPassword, encodedPassword)).isFalse(); verify(this.invalidId).matches(this.rawPassword, encodedPassword); verifyZeroInteractions(this.bcrypt, this.noop); }