Search in sources :

Example 1 with UserCredentialValue

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");
}
Also used : UserSetRequest(org.cloudfoundry.credhub.request.UserSetRequest) ArrayList(java.util.ArrayList) UserCredentialValue(org.cloudfoundry.credhub.credential.UserCredentialValue) EventAuditRecordParameters(org.cloudfoundry.credhub.audit.EventAuditRecordParameters) Test(org.junit.Test)

Example 2 with UserCredentialValue

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);
}
Also used : CertificateCredentialValue(org.cloudfoundry.credhub.credential.CertificateCredentialValue) StringCredentialValue(org.cloudfoundry.credhub.credential.StringCredentialValue) RsaCredentialValue(org.cloudfoundry.credhub.credential.RsaCredentialValue) GenerationParameters(org.cloudfoundry.credhub.request.GenerationParameters) StringGenerationParameters(org.cloudfoundry.credhub.request.StringGenerationParameters) Matchers.anyString(org.mockito.Matchers.anyString) AuditingHelper(org.cloudfoundry.credhub.helper.AuditingHelper) UserCredentialValue(org.cloudfoundry.credhub.credential.UserCredentialValue) SshCredentialValue(org.cloudfoundry.credhub.credential.SshCredentialValue) Before(org.junit.Before)

Example 3 with UserCredentialValue

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"));
}
Also used : UserCredentialValue(org.cloudfoundry.credhub.credential.UserCredentialValue) Test(org.junit.Test)

Example 4 with UserCredentialValue

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));
}
Also used : UserCredentialValue(org.cloudfoundry.credhub.credential.UserCredentialValue) StringGenerationParameters(org.cloudfoundry.credhub.request.StringGenerationParameters)

Example 5 with UserCredentialValue

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"));
}
Also used : UserCredentialValue(org.cloudfoundry.credhub.credential.UserCredentialValue) Test(org.junit.Test)

Aggregations

UserCredentialValue (org.cloudfoundry.credhub.credential.UserCredentialValue)7 Test (org.junit.Test)5 StringGenerationParameters (org.cloudfoundry.credhub.request.StringGenerationParameters)2 ArrayList (java.util.ArrayList)1 EventAuditRecordParameters (org.cloudfoundry.credhub.audit.EventAuditRecordParameters)1 CertificateCredentialValue (org.cloudfoundry.credhub.credential.CertificateCredentialValue)1 RsaCredentialValue (org.cloudfoundry.credhub.credential.RsaCredentialValue)1 SshCredentialValue (org.cloudfoundry.credhub.credential.SshCredentialValue)1 StringCredentialValue (org.cloudfoundry.credhub.credential.StringCredentialValue)1 AuditingHelper (org.cloudfoundry.credhub.helper.AuditingHelper)1 GenerationParameters (org.cloudfoundry.credhub.request.GenerationParameters)1 UserSetRequest (org.cloudfoundry.credhub.request.UserSetRequest)1 Before (org.junit.Before)1 Matchers.anyString (org.mockito.Matchers.anyString)1