Home / Class/ CredentialHelperTests Class — spring-boot Architecture

CredentialHelperTests Class — spring-boot Architecture

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

Entity Profile

Source Code

buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/configuration/CredentialHelperTests.java lines 35–115

class CredentialHelperTests {

	private static CredentialHelper helper;

	@BeforeAll
	static void setUp() throws Exception {
		helper = new CredentialHelper(getExecutableName());
	}

	private static String getExecutableName() throws Exception {
		if (Platform.isWindows()) {
			String executablePath = geExecutableAbsolutePath("docker-credential-test.bat");
			// cmd /c must resolve automatically .bat suffix
			return executablePath.substring(0, executablePath.lastIndexOf(".bat"));
		}
		return geExecutableAbsolutePath("docker-credential-test.sh");
	}

	private static String geExecutableAbsolutePath(String executableName) throws Exception {
		return new ClassPathResource(executableName, CredentialHelperTests.class).getFile().getAbsolutePath();
	}

	@Test
	void getWhenKnowUser() throws Exception {
		Credential credentials = helper.get("user.example.com");
		assertThat(credentials).isNotNull();
		assertThat(credentials.isIdentityToken()).isFalse();
		assertThat(credentials.getServerUrl()).isEqualTo("user.example.com");
		assertThat(credentials.getUsername()).isEqualTo("username");
		assertThat(credentials.getSecret()).isEqualTo("secret");
	}

	@Test
	void getWhenKnowToken() throws Exception {
		Credential credentials = helper.get("token.example.com");
		assertThat(credentials).isNotNull();
		assertThat(credentials.isIdentityToken()).isTrue();
		assertThat(credentials.getServerUrl()).isEqualTo("token.example.com");
		assertThat(credentials.getUsername()).isEqualTo("<token>");
		assertThat(credentials.getSecret()).isEqualTo("secret");
	}

	@Test
	void getWhenCredentialsMissingMessageReturnsNull() throws Exception {
		Credential credentials = helper.get("credentials.missing.example.com");
		assertThat(credentials).isNull();
	}

	@Test
	void getWhenUsernameMissingMessageReturnsNull() throws Exception {
		Credential credentials = helper.get("username.missing.example.com");
		assertThat(credentials).isNull();
	}

	@Test
	void getWhenUrlMissingMessageReturnsNull() throws Exception {
		Credential credentials = helper.get("url.missing.example.com");
		assertThat(credentials).isNull();
	}

	@Test
	void getWhenUnknownErrorThrowsException() {
		assertThatIOException().isThrownBy(() -> helper.get("invalid.example.com"))
			.withMessageContaining("Unknown error");
	}

	@Test
	void getWhenExecutableDoesNotExistErrorThrowsException() {
		String executable = "docker-credential-%s".formatted(UUID.randomUUID().toString());
		assertThatIOException().isThrownBy(() -> new CredentialHelper(executable).get("invalid.example.com"))
			.withMessageContaining(executable)
			.satisfies((ex) -> {
				if (Platform.isMac()) {
					assertThat(ex.getMessage()).doesNotContain("/usr/local/bin/");
					assertThat(ex.getSuppressed()).allSatisfy((suppressed) -> assertThat(suppressed)
						.hasMessageContaining("/usr/local/bin/" + executable));
				}
			});
	}

}

Analyze Your Own Codebase

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

Try Supermodel Free