use of org.cloudfoundry.credhub.credential.UserCredentialValue in project credhub by cloudfoundry-incubator.
the class SetHandlerTest method handleSetRequest_whenNonPasswordSetRequest_passesCorrectParametersWithNullGeneration.
@Test
public void handleSetRequest_whenNonPasswordSetRequest_passesCorrectParametersWithNullGeneration() {
UserSetRequest setRequest = new UserSetRequest();
final UserCredentialValue userCredentialValue = new UserCredentialValue("Picard", "Enterprise", "salt");
final ArrayList<EventAuditRecordParameters> eventAuditRecordParameters = new ArrayList<>();
setRequest.setType("user");
setRequest.setName("/captain");
setRequest.setAdditionalPermissions(accessControlEntries);
setRequest.setOverwrite(false);
setRequest.setUserValue(userCredentialValue);
subject.handle(setRequest, eventAuditRecordParameters);
verify(credentialService).save(null, userCredentialValue, setRequest, eventAuditRecordParameters);
verify(permissionService).savePermissions(credentialVersion, accessControlEntries, eventAuditRecordParameters, true, "/captain");
}
use of org.cloudfoundry.credhub.credential.UserCredentialValue in project credhub by cloudfoundry-incubator.
the class CredentialsControllerTypeSpecificGenerateTest method setup.
@Before
public void setup() throws Exception {
String fakeSalt = cryptSaltFactory.generateSalt(FAKE_PASSWORD);
Consumer<Long> fakeTimeSetter = mockOutCurrentTimeProvider(mockCurrentTimeProvider);
fakeTimeSetter.accept(FROZEN_TIME.toEpochMilli());
mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
when(passwordGenerator.generateCredential(any(GenerationParameters.class))).thenReturn(new StringCredentialValue(FAKE_PASSWORD));
when(certificateGenerator.generateCredential(any(GenerationParameters.class))).thenReturn(new CertificateCredentialValue(CA, CERTIFICATE, PRIVATE_KEY, null));
when(sshGenerator.generateCredential(any(GenerationParameters.class))).thenReturn(new SshCredentialValue(PUBLIC_KEY, PRIVATE_KEY, null));
when(rsaGenerator.generateCredential(any(GenerationParameters.class))).thenReturn(new RsaCredentialValue(PUBLIC_KEY, PRIVATE_KEY));
when(userGenerator.generateCredential(any(GenerationParameters.class))).thenReturn(new UserCredentialValue(USERNAME, FAKE_PASSWORD, fakeSalt));
auditingHelper = new AuditingHelper(requestAuditRecordRepository, eventAuditRecordRepository);
}
use of org.cloudfoundry.credhub.credential.UserCredentialValue in project credhub by cloudfoundry-incubator.
the class UserSetRequestTest method whenAllFieldsAreSet_shouldHaveValidValueField.
@Test
public void whenAllFieldsAreSet_shouldHaveValidValueField() {
UserSetRequest userSetRequest = JsonTestHelper.deserialize(validSetRequestJson, UserSetRequest.class);
UserCredentialValue userValue = userSetRequest.getUserValue();
assertThat(userValue.getUsername(), equalTo("dan"));
assertThat(userValue.getPassword(), equalTo("example-password"));
}
use of org.cloudfoundry.credhub.credential.UserCredentialValue in project credhub by cloudfoundry-incubator.
the class UserGenerator method generateCredential.
public UserCredentialValue generateCredential(GenerationParameters p) {
StringGenerationParameters params = (StringGenerationParameters) p;
String username = params.getUsername();
if (username == null) {
username = usernameGenerator.generateCredential().getStringCredential();
}
String password = passwordGenerator.generateCredential(params).getStringCredential();
return new UserCredentialValue(username, password, cryptSaltFactory.generateSalt(password));
}
use of org.cloudfoundry.credhub.credential.UserCredentialValue in project credhub by cloudfoundry-incubator.
the class UserGeneratorTest method generateCredential_givenNoUsernameAndPasswordParameters_generatesUserWithGeneratedUsernameAndPassword.
@Test
public void generateCredential_givenNoUsernameAndPasswordParameters_generatesUserWithGeneratedUsernameAndPassword() {
final UserCredentialValue user = subject.generateCredential(passwordParameters);
assertThat(user.getUsername(), equalTo("fake-generated-username"));
assertThat(user.getPassword(), equalTo("fake-generated-password"));
assertThat(user.getSalt(), equalTo("fake-generated-salt"));
}
Aggregations