Home / Class/ EncodePasswordCommandTests Class — spring-boot Architecture

EncodePasswordCommandTests Class — spring-boot Architecture

Architecture documentation for the EncodePasswordCommandTests class in EncodePasswordCommandTests.java from the spring-boot codebase.

Entity Profile

Relationship Graph

Source Code

cli/spring-boot-cli/src/test/java/org/springframework/boot/cli/command/encodepassword/EncodePasswordCommandTests.java lines 41–108

@ExtendWith(MockitoExtension.class)
class EncodePasswordCommandTests {

	private MockLog log;

	@BeforeEach
	void setup() {
		this.log = MockLog.attach();
	}

	@AfterEach
	void cleanup() {
		MockLog.clear();
	}

	@Test
	void encodeWithNoAlgorithmShouldUseBcrypt() throws Exception {
		EncodePasswordCommand command = new EncodePasswordCommand();
		ExitStatus status = command.run("boot");
		then(this.log).should().info(assertArg((message) -> {
			assertThat(message).startsWith("{bcrypt}");
			assertThat(PasswordEncoderFactories.createDelegatingPasswordEncoder().matches("boot", message)).isTrue();
		}));
		assertThat(status).isEqualTo(ExitStatus.OK);
	}

	@Test
	void encodeWithDefaultShouldUseBcrypt() throws Exception {
		EncodePasswordCommand command = new EncodePasswordCommand();
		ExitStatus status = command.run("-a", "default", "boot");
		then(this.log).should().info(assertArg((message) -> {
			assertThat(message).startsWith("{bcrypt}");
			assertThat(PasswordEncoderFactories.createDelegatingPasswordEncoder().matches("boot", message)).isTrue();
		}));
		assertThat(status).isEqualTo(ExitStatus.OK);
	}

	@Test
	void encodeWithBCryptShouldUseBCrypt() throws Exception {
		EncodePasswordCommand command = new EncodePasswordCommand();
		ExitStatus status = command.run("-a", "bcrypt", "boot");
		then(this.log).should().info(assertArg((message) -> {
			assertThat(message).doesNotStartWith("{");
			assertThat(new BCryptPasswordEncoder().matches("boot", message)).isTrue();
		}));
		assertThat(status).isEqualTo(ExitStatus.OK);
	}

	@Test
	void encodeWithPbkdf2ShouldUsePbkdf2() throws Exception {
		EncodePasswordCommand command = new EncodePasswordCommand();
		ExitStatus status = command.run("-a", "pbkdf2", "boot");
		then(this.log).should().info(assertArg((message) -> {
			assertThat(message).doesNotStartWith("{");
			assertThat(Pbkdf2PasswordEncoder.defaultsForSpringSecurity_v5_8().matches("boot", message)).isTrue();
		}));
		assertThat(status).isEqualTo(ExitStatus.OK);
	}

	@Test
	void encodeWithUnknownAlgorithmShouldExitWithError() throws Exception {
		EncodePasswordCommand command = new EncodePasswordCommand();
		ExitStatus status = command.run("--algorithm", "bad", "boot");
		then(this.log).should().error("Unknown algorithm, valid options are: default,bcrypt,pbkdf2");
		assertThat(status).isEqualTo(ExitStatus.ERROR);
	}

}

Domain

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free