org.springframework.credhub.support.CredentialType Java Examples

The following examples show how to use org.springframework.credhub.support.CredentialType. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CredHubCredentialsGeneratorTest.java    From spring-cloud-app-broker with Apache License 2.0 6 votes vote down vote up
@Test
void generateString() {
	given(this.credHubOperations.credentials())
		.willReturn(credHubCredentialOperations);

	CredentialDetails<PasswordCredential> creds = new CredentialDetails<>("id",
		new SimpleCredentialName("app-service"), CredentialType.PASSWORD,
		new PasswordCredential("password"));

	given(this.credHubCredentialOperations.generate(any(), eq(PasswordCredential.class)))
		.willReturn(Mono.just(creds));

	StepVerifier.create(generator.generateString("foo", "bar", "hello", 12, false, false, false, false))
		.assertNext(password -> assertThat(password).isEqualTo("password"))
		.verifyComplete();
}
 
Example #2
Source File: CredhubIntegrationTest.java    From spring-cloud-config with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() {
	CredHubCredentialOperations credhubCredentialOperations = Mockito
			.mock(CredHubCredentialOperations.class);

	String expectedPath = "/myapp/master/default";
	SimpleCredentialName togglesCredentialName = new SimpleCredentialName(
			expectedPath + "/toggles");
	when(credhubCredentialOperations.findByPath(expectedPath))
			.thenReturn(singletonList(new CredentialSummary(togglesCredentialName)));
	JsonCredential credentials = new JsonCredential();
	credentials.put("key", "value");
	when(credhubCredentialOperations.getByName(
			new SimpleCredentialName(expectedPath + "/toggles"),
			JsonCredential.class))
					.thenReturn(new CredentialDetails<>("id1", togglesCredentialName,
							CredentialType.JSON, credentials));

	when(this.credHubOperations.credentials())
			.thenReturn(credhubCredentialOperations);
}
 
Example #3
Source File: CredHubCertificateTemplateUnitTests.java    From spring-credhub with Apache License 2.0 6 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void regenerate() {
	CertificateCredentialDetails expectedCertificate = new CertificateCredentialDetails("id", NAME,
			CredentialType.CERTIFICATE, true, new CertificateCredential("cert", "authority", "key"));

	Map<String, Boolean> request = new HashMap<>();
	request.put(CredHubCertificateTemplate.TRANSITIONAL_REQUEST_FIELD, true);

	given(this.restTemplate.exchange(eq(CredHubCertificateTemplate.REGENERATE_URL_PATH), eq(HttpMethod.POST),
			eq(new HttpEntity<>(request)), isA(ParameterizedTypeReference.class), eq("id")))
					.willReturn(new ResponseEntity<>(expectedCertificate, HttpStatus.OK));

	CertificateCredentialDetails response = this.credHubTemplate.regenerate("id", true);

	assertThat(response).isNotNull();
	assertThat(response.getId()).isEqualTo("id");
	assertThat(response.getCredentialType()).isEqualTo(CredentialType.CERTIFICATE);
	assertThat(response.isTransitional()).isTrue();
	assertThat(response.getValue().getCertificate()).isEqualTo("cert");
	assertThat(response.getValue().getCertificateAuthority()).isEqualTo("authority");
	assertThat(response.getValue().getPrivateKey()).isEqualTo("key");
}
 
Example #4
Source File: ReactiveCredentialIntegrationTests.java    From spring-credhub with Apache License 2.0 6 votes vote down vote up
private void verifyHistory() {
	StepVerifier.create(this.credentials.getByNameWithHistory(CREDENTIAL_NAME, ValueCredential.class))
			.assertNext((response) -> {
				assertThat(response.getName().getName()).isEqualTo(CREDENTIAL_NAME.getName());
				assertThat(response.getValue().getValue()).isEqualTo("new-value");
				assertThat(response.getCredentialType()).isEqualTo(CredentialType.VALUE);
			}).assertNext((response) -> {
				assertThat(response.getName().getName()).isEqualTo(CREDENTIAL_NAME.getName());
				assertThat(response.getValue().getValue()).isEqualTo(CREDENTIAL_VALUE);
				assertThat(response.getCredentialType()).isEqualTo(CredentialType.VALUE);
			}).verifyComplete();

	StepVerifier.create(this.credentials.getByNameWithHistory(CREDENTIAL_NAME, 2, ValueCredential.class))
			.assertNext((response) -> {
				assertThat(response.getName().getName()).isEqualTo(CREDENTIAL_NAME.getName());
				assertThat(response.getValue().getValue()).isEqualTo("new-value");
				assertThat(response.getCredentialType()).isEqualTo(CredentialType.VALUE);
			}).assertNext((response) -> {
				assertThat(response.getName().getName()).isEqualTo(CREDENTIAL_NAME.getName());
				assertThat(response.getValue().getValue()).isEqualTo(CREDENTIAL_VALUE);
				assertThat(response.getCredentialType()).isEqualTo(CredentialType.VALUE);
			}).verifyComplete();
}
 
Example #5
Source File: ReactiveCredentialIntegrationTests.java    From spring-credhub with Apache License 2.0 6 votes vote down vote up
@Test
public void overwriteCredentialV2() {
	assumeTrue(serverApiIsV2());

	StepVerifier
			.create(this.credentials
					.write(ValueCredentialRequest.builder().name(CREDENTIAL_NAME).value(CREDENTIAL_VALUE).build()))
			.assertNext((response) -> {
				assertThat(response.getName().getName()).isEqualTo(CREDENTIAL_NAME.getName());
				assertThat(response.getValue().getValue()).isEqualTo(CREDENTIAL_VALUE);
				assertThat(response.getCredentialType()).isEqualTo(CredentialType.VALUE);
				assertThat(response.getId()).isNotNull();
			}).verifyComplete();

	StepVerifier
			.create(this.credentials
					.write(ValueCredentialRequest.builder().name(CREDENTIAL_NAME).value("new-value").build()))
			.assertNext((response) -> {
				assertThat(response.getName().getName()).isEqualTo(CREDENTIAL_NAME.getName());
				assertThat(response.getValue().getValue()).isEqualTo("new-value");
			}).verifyComplete();

	verifyHistory();
}
 
Example #6
Source File: ReactiveCertificateIntegrationTests.java    From spring-credhub with Apache License 2.0 6 votes vote down vote up
@Test
public void generateCertificate() {
	assumeTrue(serverApiIsV2());

	StepVerifier.create(this.credentials.generate(CertificateParametersRequest.builder().name(TEST_CERT_NAME)
			.parameters(CertificateParameters.builder().commonName("example.com").selfSign(true).build()).build(),
			CertificateCredential.class)).assertNext((response) -> {
				assertThat(response.getName().getName()).isEqualTo(TEST_CERT_NAME.getName());
				assertThat(response.getCredentialType()).isEqualTo(CredentialType.CERTIFICATE);
				assertThat(response.getId()).isNotNull();
				assertThat(response.getValue().getCertificate()).isNotNull();
				assertThat(response.getValue().getCertificateAuthority()).isNotNull();
				assertThat(response.getValue().getPrivateKey()).isNotNull();
			}).verifyComplete();

	StepVerifier.create(this.certificates.getByName(TEST_CERT_NAME)).assertNext((response) -> {
		assertThat(response.getName()).isEqualTo(TEST_CERT_NAME.getName());
		assertThat(response.getId()).isNotNull();
	}).verifyComplete();

	StepVerifier.create(this.certificates.getAll())
			.assertNext((response) -> assertThat(response.getName()).isEqualTo(TEST_CERT_NAME.getName()))
			.thenCancel().verify();
}
 
Example #7
Source File: CredentialIntegrationTests.java    From spring-credhub with Apache License 2.0 6 votes vote down vote up
@Test
public void generateCredential() {
	CredentialDetails<UserCredential> generated = this.credentials.generate(UserParametersRequest.builder()
			.name(CREDENTIAL_NAME).username("test-user").parameters(this.passwordParameters.build()).build());
	assertThat(generated.getName().getName()).isEqualTo(CREDENTIAL_NAME.getName());
	assertThat(generated.getCredentialType()).isEqualTo(CredentialType.USER);
	assertThat(generated.getValue().getUsername()).isEqualTo("test-user");
	assertThat(generated.getValue().getPassword()).matches("^[a-zA-Z0-9\\p{Punct}]{12}$");
	assertThat(generated.getValue().getPasswordHash()).isNotNull();

	CredentialDetails<UserCredential> retrieved = this.credentials.getById(generated.getId(), UserCredential.class);
	assertThat(retrieved.getName().getName()).isEqualTo(CREDENTIAL_NAME.getName());

	CredentialDetails<UserCredential> regenerated = this.credentials.regenerate(CREDENTIAL_NAME,
			UserCredential.class);
	assertThat(regenerated.getName().getName()).isEqualTo(CREDENTIAL_NAME.getName());
	assertThat(regenerated.getValue().getUsername()).isEqualTo("test-user");
	assertThat(regenerated.getValue().getPassword()).matches("^[a-zA-Z0-9\\p{Punct}]{12}$");
	assertThat(regenerated.getValue().getPassword()).isNotEqualTo(generated.getValue().getPassword());
	assertThat(regenerated.getValue().getPasswordHash()).isNotEqualTo(generated.getValue().getPasswordHash());
}
 
Example #8
Source File: CredHubCredentialsGeneratorTest.java    From spring-cloud-app-broker with Apache License 2.0 6 votes vote down vote up
@Test
void generateUser() {
	given(this.credHubOperations.credentials())
		.willReturn(credHubCredentialOperations);

	CredentialDetails<UserCredential> creds = new CredentialDetails<>("id",
		new SimpleCredentialName("app-service"), CredentialType.PASSWORD,
		new UserCredential("username", "password"));

	given(this.credHubCredentialOperations.generate(any(), eq(UserCredential.class)))
		.willReturn(Mono.just(creds));

	StepVerifier.create(generator.generateUser("foo", "bar", "hello", 12, false, false, false, false))
		.assertNext(tuple2 -> {
			assertThat(tuple2.getT1()).isEqualTo("username");
			assertThat(tuple2.getT2()).isEqualTo("password");
		})
		.verifyComplete();
}
 
Example #9
Source File: CredentialIntegrationTests.java    From spring-credhub with Apache License 2.0 6 votes vote down vote up
@Test
public void overwriteCredentialV2() {
	assumeTrue(serverApiIsV2());

	CredentialDetails<ValueCredential> written = this.credentials
			.write(ValueCredentialRequest.builder().name(CREDENTIAL_NAME).value(CREDENTIAL_VALUE).build());
	assertThat(written.getName().getName()).isEqualTo(CREDENTIAL_NAME.getName());
	assertThat(written.getValue().getValue()).isEqualTo(CREDENTIAL_VALUE);
	assertThat(written.getCredentialType()).isEqualTo(CredentialType.VALUE);
	assertThat(written.getId()).isNotNull();

	CredentialDetails<ValueCredential> overwritten = this.credentials
			.write(ValueCredentialRequest.builder().name(CREDENTIAL_NAME).value("new-value").build());
	assertThat(overwritten.getName().getName()).isEqualTo(CREDENTIAL_NAME.getName());
	assertThat(overwritten.getValue().getValue()).isEqualTo("new-value");

	verifyHistory();
}
 
Example #10
Source File: CertificateIntegrationTests.java    From spring-credhub with Apache License 2.0 6 votes vote down vote up
@Test
public void generateCertificate() {
	assumeTrue(serverApiIsV2());

	CredentialDetails<CertificateCredential> certificate = this.credentials.generate(CertificateParametersRequest
			.builder().name(TEST_CERT_NAME)
			.parameters(CertificateParameters.builder().commonName("example.com").selfSign(true).build()).build());
	assertThat(certificate.getName().getName()).isEqualTo(TEST_CERT_NAME.getName());
	assertThat(certificate.getCredentialType()).isEqualTo(CredentialType.CERTIFICATE);
	assertThat(certificate.getId()).isNotNull();
	assertThat(certificate.getValue().getCertificate()).isNotNull();
	assertThat(certificate.getValue().getCertificateAuthority()).isNotNull();
	assertThat(certificate.getValue().getPrivateKey()).isNotNull();

	CertificateSummary byName = this.certificates.getByName(TEST_CERT_NAME);
	assertThat(byName.getName()).isEqualTo(TEST_CERT_NAME.getName());
	assertThat(byName.getId()).isNotNull();

	List<CertificateSummary> allCertificates = this.certificates.getAll();
	assertThat(allCertificates.size()).isGreaterThan(0);
	assertThat(allCertificates).extracting("name").contains(TEST_CERT_NAME.getName());
}
 
Example #11
Source File: CredentialIntegrationTests.java    From spring-credhub with Apache License 2.0 6 votes vote down vote up
@Test
public void overwriteCredentialV1() {
	assumeTrue(serverApiIsV1());

	CredentialDetails<ValueCredential> written = this.credentials
			.write(ValueCredentialRequest.builder().name(CREDENTIAL_NAME).value(CREDENTIAL_VALUE).build());
	assertThat(written.getName().getName()).isEqualTo(CREDENTIAL_NAME.getName());
	assertThat(written.getValue().getValue()).isEqualTo(CREDENTIAL_VALUE);
	assertThat(written.getCredentialType()).isEqualTo(CredentialType.VALUE);
	assertThat(written.getId()).isNotNull();

	CredentialDetails<ValueCredential> overwritten = this.credentials.write(ValueCredentialRequest.builder()
			.name(CREDENTIAL_NAME).value("new-value").mode(WriteMode.NO_OVERWRITE).build());
	assertThat(overwritten.getName().getName()).isEqualTo(CREDENTIAL_NAME.getName());
	assertThat(overwritten.getValue().getValue()).isEqualTo(CREDENTIAL_VALUE);

	overwritten = this.credentials.write(ValueCredentialRequest.builder().name(CREDENTIAL_NAME).value("new-value")
			.mode(WriteMode.OVERWRITE).build());
	assertThat(overwritten.getName().getName()).isEqualTo(CREDENTIAL_NAME.getName());
	assertThat(overwritten.getValue().getValue()).isEqualTo("new-value");

	verifyHistory();
}
 
Example #12
Source File: UserCredentialDetailsUnitTests.java    From spring-credhub with Apache License 2.0 5 votes vote down vote up
private void assertDetails(CredentialDetails<UserCredential> data) {
	assertCommonDetails(data);

	assertThat(data.getCredentialType()).isEqualTo(CredentialType.USER);
	assertThat(data.getValue().getUsername()).isEqualTo("myname");
	assertThat(data.getValue().getPassword()).isEqualTo("secret");
	assertThat(data.getValue().getPasswordHash()).isEqualTo("secret-hash");
}
 
Example #13
Source File: CredhubEnvironmentRepositoryTests.java    From spring-cloud-config with Apache License 2.0 5 votes vote down vote up
private void stubCredentials(String expectedPath, String name, String key,
		String value) {
	SimpleCredentialName credentialsName = new SimpleCredentialName(
			expectedPath + "/" + name);
	when(this.credhubCredentialOperations.findByPath(expectedPath))
			.thenReturn(singletonList(new CredentialSummary(credentialsName)));
	JsonCredential credentials = new JsonCredential();
	credentials.put(key, value);
	when(this.credhubCredentialOperations.getByName(
			new SimpleCredentialName(expectedPath + "/" + name),
			JsonCredential.class))
					.thenReturn(new CredentialDetails<>("id1", credentialsName,
							CredentialType.JSON, credentials));
}
 
Example #14
Source File: CredHubCertificateTemplateUnitTests.java    From spring-credhub with Apache License 2.0 5 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void updateTransitionalVersion() {
	List<CertificateCredentialDetails> expectedCertificates = Arrays.asList(
			new CertificateCredentialDetails("id1", NAME, CredentialType.CERTIFICATE, false,
					new CertificateCredential("cert1", "authority1", "key1")),
			new CertificateCredentialDetails("id2", NAME, CredentialType.CERTIFICATE, true,
					new CertificateCredential("cert2", "authority2", "key2")));

	Map<String, String> request = new HashMap<>();
	request.put(CredHubCertificateTemplate.VERSION_REQUEST_FIELD, "id2");

	given(this.restTemplate.exchange(eq(CredHubCertificateTemplate.UPDATE_TRANSITIONAL_URL_PATH),
			eq(HttpMethod.PUT), eq(new HttpEntity<>(request)), isA(ParameterizedTypeReference.class), eq("id1")))
					.willReturn(new ResponseEntity<>(expectedCertificates, HttpStatus.OK));

	List<CertificateCredentialDetails> response = this.credHubTemplate.updateTransitionalVersion("id1", "id2");

	assertThat(response).hasSize(2);
	assertThat(response).extracting("id").contains("id1", "id2");
	assertThat(response).extracting("credentialType").contains(CredentialType.CERTIFICATE,
			CredentialType.CERTIFICATE);
	assertThat(response).extracting("transitional").contains(false, true);
	assertThat(response).extracting("value.certificate").contains("cert1", "cert2");
	assertThat(response).extracting("value.certificateAuthority").contains("authority1", "authority2");
	assertThat(response).extracting("value.privateKey").contains("key1", "key2");
}
 
Example #15
Source File: CredentialIntegrationTests.java    From spring-credhub with Apache License 2.0 5 votes vote down vote up
@Test
public void writeCredential() {
	CredentialDetails<ValueCredential> written = this.credentials
			.write(ValueCredentialRequest.builder().name(CREDENTIAL_NAME).value(CREDENTIAL_VALUE).build());
	assertThat(written.getName().getName()).isEqualTo(CREDENTIAL_NAME.getName());
	assertThat(written.getValue().getValue()).isEqualTo(CREDENTIAL_VALUE);
	assertThat(written.getCredentialType()).isEqualTo(CredentialType.VALUE);
	assertThat(written.getId()).isNotNull();

	CredentialDetails<ValueCredential> byId = this.credentials.getById(written.getId(), ValueCredential.class);
	assertThat(byId.getName().getName()).isEqualTo(CREDENTIAL_NAME.getName());
	assertThat(byId.getValue().getValue()).isEqualTo(CREDENTIAL_VALUE);
	assertThat(byId.getCredentialType()).isEqualTo(CredentialType.VALUE);

	CredentialDetails<ValueCredential> byName = this.credentials.getByName(CREDENTIAL_NAME, ValueCredential.class);
	assertThat(byName.getName().getName()).isEqualTo(CREDENTIAL_NAME.getName());
	assertThat(byName.getValue().getValue()).isEqualTo(CREDENTIAL_VALUE);
	assertThat(byName.getCredentialType()).isEqualTo(CredentialType.VALUE);

	List<CredentialSummary> foundByName = this.credentials.findByName(new SimpleCredentialName("/test"));
	assertThat(foundByName).hasSize(1);
	assertThat(foundByName).extracting("name").extracting("name").containsExactly(CREDENTIAL_NAME.getName());

	List<CredentialSummary> foundByPath = this.credentials.findByPath("/spring-credhub/integration-test");
	assertThat(foundByPath).hasSize(1);
	assertThat(foundByPath).extracting("name").extracting("name").containsExactly(CREDENTIAL_NAME.getName());
}
 
Example #16
Source File: SshCredentialDetailsUnitTests.java    From spring-credhub with Apache License 2.0 5 votes vote down vote up
private void assertDetails(CredentialDetails<SshCredential> data, String publicKey, String privateKey,
		String publicKeyFingerprint) {
	assertCommonDetails(data);

	assertThat(data.getCredentialType()).isEqualTo(CredentialType.SSH);
	assertThat(data.getValue().getPublicKey()).isEqualTo(publicKey);
	assertThat(data.getValue().getPrivateKey()).isEqualTo(privateKey);
	assertThat(data.getValue().getPublicKeyFingerprint()).isEqualTo(publicKeyFingerprint);
}
 
Example #17
Source File: RsaCredentialDetailsUnitTests.java    From spring-credhub with Apache License 2.0 5 votes vote down vote up
private void assertDetails(CredentialDetails<RsaCredential> data, String publicKey, String privateKey) {
	assertCommonDetails(data);

	assertThat(data.getCredentialType()).isEqualTo(CredentialType.RSA);
	assertThat(data.getValue().getPublicKey()).isEqualTo(publicKey);
	assertThat(data.getValue().getPrivateKey()).isEqualTo(privateKey);
}
 
Example #18
Source File: JsonCredentialDetailsUnitTests.java    From spring-credhub with Apache License 2.0 5 votes vote down vote up
private void assertDetails(CredentialDetails<JsonCredential> data) {
	assertCommonDetails(data);

	assertThat(data.getCredentialType()).isEqualTo(CredentialType.JSON);

	JsonCredential valueMap = data.getValue();
	assertThat(valueMap).containsEntry("client_id", "test-id").containsEntry("client_secret", "test-secret")
			.containsEntry("uri", "https://example.com");
}
 
Example #19
Source File: CertificateCredentialDetailsUnitTests.java    From spring-credhub with Apache License 2.0 5 votes vote down vote up
private void assertDetails(CredentialDetails<CertificateCredential> data, String certificate, String ca,
		String privateKey) {
	assertCommonDetails(data);

	assertThat(data.getCredentialType()).isEqualTo(CredentialType.CERTIFICATE);
	assertThat(data.getValue().getCertificate()).isEqualTo(certificate);
	assertThat(data.getValue().getCertificateAuthority()).isEqualTo(ca);
	assertThat(data.getValue().getPrivateKey()).isEqualTo(privateKey);
}
 
Example #20
Source File: ReactiveCredentialIntegrationTests.java    From spring-credhub with Apache License 2.0 5 votes vote down vote up
@Test
public void overwriteCredentialV1() {
	assumeTrue(serverApiIsV1());

	StepVerifier
			.create(this.credentials
					.write(ValueCredentialRequest.builder().name(CREDENTIAL_NAME).value(CREDENTIAL_VALUE).build()))
			.assertNext((response) -> {
				assertThat(response.getName().getName()).isEqualTo(CREDENTIAL_NAME.getName());
				assertThat(response.getValue().getValue()).isEqualTo(CREDENTIAL_VALUE);
				assertThat(response.getCredentialType()).isEqualTo(CredentialType.VALUE);
				assertThat(response.getId()).isNotNull();
			}).verifyComplete();

	StepVerifier.create(this.credentials.write(ValueCredentialRequest.builder().name(CREDENTIAL_NAME)
			.value("new-value").mode(WriteMode.NO_OVERWRITE).build())).assertNext((response) -> {
				assertThat(response.getName().getName()).isEqualTo(CREDENTIAL_NAME.getName());
				assertThat(response.getValue().getValue()).isEqualTo(CREDENTIAL_VALUE);
			}).verifyComplete();

	StepVerifier.create(this.credentials.write(ValueCredentialRequest.builder().name(CREDENTIAL_NAME)
			.value("new-value").mode(WriteMode.OVERWRITE).build())).assertNext((response) -> {
				assertThat(response.getName().getName()).isEqualTo(CREDENTIAL_NAME.getName());
				assertThat(response.getValue().getValue()).isEqualTo("new-value");
			}).verifyComplete();

	verifyHistory();
}
 
Example #21
Source File: ReactiveCredentialIntegrationTests.java    From spring-credhub with Apache License 2.0 5 votes vote down vote up
@Test
public void writeCredential() {
	AtomicReference<CredentialDetails<ValueCredential>> written = new AtomicReference<>();

	StepVerifier
			.create(this.credentials
					.write(ValueCredentialRequest.builder().name(CREDENTIAL_NAME).value(CREDENTIAL_VALUE).build()))
			.assertNext((response) -> {
				assertThat(response.getName().getName()).isEqualTo(CREDENTIAL_NAME.getName());
				assertThat(response.getValue().getValue()).isEqualTo(CREDENTIAL_VALUE);
				assertThat(response.getCredentialType()).isEqualTo(CredentialType.VALUE);
				assertThat(response.getId()).isNotNull();

				written.set(response);
			}).verifyComplete();

	StepVerifier.create(this.credentials.getById(written.get().getId(), ValueCredential.class))
			.assertNext((response) -> {
				assertThat(response.getName().getName()).isEqualTo(CREDENTIAL_NAME.getName());
				assertThat(response.getValue().getValue()).isEqualTo(CREDENTIAL_VALUE);
				assertThat(response.getCredentialType()).isEqualTo(CredentialType.VALUE);
			}).verifyComplete();

	StepVerifier.create(this.credentials.getByName(CREDENTIAL_NAME, ValueCredential.class))
			.assertNext((response) -> {
				assertThat(response.getName().getName()).isEqualTo(CREDENTIAL_NAME.getName());
				assertThat(response.getValue().getValue()).isEqualTo(CREDENTIAL_VALUE);
				assertThat(response.getCredentialType()).isEqualTo(CredentialType.VALUE);
			}).verifyComplete();

	StepVerifier.create(this.credentials.findByName(new SimpleCredentialName("/test")))
			.assertNext((response) -> assertThat(response).extracting("name").extracting("name")
					.containsExactly(CREDENTIAL_NAME.getName()))
			.verifyComplete();

	StepVerifier.create(this.credentials.findByPath("/spring-credhub/integration-test"))
			.assertNext((response) -> assertThat(response).extracting("name").extracting("name")
					.containsExactly(CREDENTIAL_NAME.getName()))
			.verifyComplete();
}
 
Example #22
Source File: ReactiveCredentialIntegrationTests.java    From spring-credhub with Apache License 2.0 5 votes vote down vote up
@Test
public void generateCredential() {
	AtomicReference<CredentialDetails<UserCredential>> generated = new AtomicReference<>();

	StepVerifier.create(this.credentials.generate(UserParametersRequest.builder().name(CREDENTIAL_NAME)
			.username("test-user").parameters(this.passwordParameters.build()).build(), UserCredential.class))
			.assertNext((response) -> {
				assertThat(response.getName().getName()).isEqualTo(CREDENTIAL_NAME.getName());
				assertThat(response.getCredentialType()).isEqualTo(CredentialType.USER);
				assertThat(response.getValue().getUsername()).isEqualTo("test-user");
				assertThat(response.getValue().getPassword()).matches("^[a-zA-Z0-9\\p{Punct}]{12}$");
				assertThat(response.getValue().getPasswordHash()).isNotNull();

				generated.set(response);
			}).verifyComplete();

	StepVerifier.create(this.credentials.getById(generated.get().getId(), UserCredential.class))
			.assertNext((response) -> assertThat(response.getName().getName()).isEqualTo(CREDENTIAL_NAME.getName()))
			.verifyComplete();

	StepVerifier.create(this.credentials.regenerate(CREDENTIAL_NAME, UserCredential.class))
			.assertNext((response) -> {
				assertThat(response.getName().getName()).isEqualTo(CREDENTIAL_NAME.getName());
				assertThat(response.getValue().getUsername()).isEqualTo("test-user");
				assertThat(response.getValue().getPassword()).matches("^[a-zA-Z0-9\\p{Punct}]{12}$");
				assertThat(response.getValue().getPassword())
						.isNotEqualTo(generated.get().getValue().getPassword());
				assertThat(response.getValue().getPasswordHash())
						.isNotEqualTo(generated.get().getValue().getPasswordHash());
			}).verifyComplete();
}
 
Example #23
Source File: JsonUtils.java    From spring-credhub with Apache License 2.0 5 votes vote down vote up
/**
 * Configure type mapping for the {@literal value} field in the
 * {@literal CredentialDetails} object.
 * @param objectMapper the {@link ObjectMapper} to configure
 */
private static void configureCredentialDetailTypeMapping(ObjectMapper objectMapper) {
	List<NamedType> subtypes = new ArrayList<>();
	for (CredentialType type : CredentialType.values()) {
		subtypes.add(new NamedType(type.getModelClass(), type.getValueType()));
	}

	registerSubtypes(objectMapper, subtypes);
}
 
Example #24
Source File: CredHubTemplateDetailValueUnitTests.java    From spring-credhub with Apache License 2.0 4 votes vote down vote up
@DataPoints("data-responses")
public static List<ResponseEntity<CredentialDetailsData<ValueCredential>>> buildDataResponses() {
	return buildDataResponses(CredentialType.VALUE, CREDENTIAL);
}
 
Example #25
Source File: CredHubTemplateDetailUserUnitTests.java    From spring-credhub with Apache License 2.0 4 votes vote down vote up
@DataPoints("data-responses")
public static List<ResponseEntity<CredentialDetailsData<UserCredential>>> buildDataResponses() {
	return buildDataResponses(CredentialType.USER, CREDENTIAL);
}
 
Example #26
Source File: CredHubTemplateDetailPasswordUnitTests.java    From spring-credhub with Apache License 2.0 4 votes vote down vote up
@DataPoints("detail-responses")
public static List<ResponseEntity<CredentialDetails<PasswordCredential>>> buildDetailResponses() {
	return buildDetailResponses(CredentialType.PASSWORD, CREDENTIAL);
}
 
Example #27
Source File: CredHubTemplateDetailPasswordUnitTests.java    From spring-credhub with Apache License 2.0 4 votes vote down vote up
@DataPoints("data-responses")
public static List<ResponseEntity<CredentialDetailsData<PasswordCredential>>> buildDataResponses() {
	return buildDataResponses(CredentialType.PASSWORD, CREDENTIAL);
}
 
Example #28
Source File: CredHubTemplateDetailRsaUnitTests.java    From spring-credhub with Apache License 2.0 4 votes vote down vote up
@DataPoints("detail-responses")
public static List<ResponseEntity<CredentialDetails<RsaCredential>>> buildDetailResponses() {
	return buildDetailResponses(CredentialType.RSA, CREDENTIAL);
}
 
Example #29
Source File: CredHubTemplateDetailRsaUnitTests.java    From spring-credhub with Apache License 2.0 4 votes vote down vote up
@DataPoints("data-responses")
public static List<ResponseEntity<CredentialDetailsData<RsaCredential>>> buildDataResponses() {
	return buildDataResponses(CredentialType.RSA, CREDENTIAL);
}
 
Example #30
Source File: CredHubTemplateDetailCertificateUnitTests.java    From spring-credhub with Apache License 2.0 4 votes vote down vote up
@DataPoints("detail-responses")
public static List<ResponseEntity<CredentialDetails<CertificateCredential>>> buildDetailResponses() {
	return buildDetailResponses(CredentialType.CERTIFICATE, CREDENTIAL);
}