Search in sources :

Example 1 with PersonalAccessTokenNewValue

use of org.sonar.db.audit.model.PersonalAccessTokenNewValue in project sonarqube by SonarSource.

the class AlmPatDao method update.

public void update(DbSession dbSession, AlmPatDto almPatDto, @Nullable String userLogin, @Nullable String almSettingKey) {
    long now = system2.now();
    almPatDto.setUpdatedAt(now);
    getMapper(dbSession).update(almPatDto);
    auditPersister.updatePersonalAccessToken(dbSession, new PersonalAccessTokenNewValue(almPatDto, userLogin, almSettingKey));
}
Also used : PersonalAccessTokenNewValue(org.sonar.db.audit.model.PersonalAccessTokenNewValue)

Example 2 with PersonalAccessTokenNewValue

use of org.sonar.db.audit.model.PersonalAccessTokenNewValue in project sonarqube by SonarSource.

the class AlmPatDaoWithPersisterTest method deleteByAlmSettingIsPersisted.

@Test
public void deleteByAlmSettingIsPersisted() {
    when(uuidFactory.create()).thenReturn(A_UUID);
    AlmSettingDto almSettingDto = db.almSettings().insertBitbucketAlmSetting();
    AlmPatDto almPat = newAlmPatDto();
    almPat.setAlmSettingUuid(almSettingDto.getUuid());
    underTest.insert(dbSession, almPat, null, almSettingDto.getKey());
    verify(auditPersister).addPersonalAccessToken(eq(dbSession), newValueCaptor.capture());
    underTest.deleteByAlmSetting(dbSession, almSettingDto);
    verify(auditPersister).deletePersonalAccessToken(eq(dbSession), newValueCaptor.capture());
    PersonalAccessTokenNewValue newValue = newValueCaptor.getValue();
    assertThat(newValue).extracting(PersonalAccessTokenNewValue::getPatUuid, PersonalAccessTokenNewValue::getAlmSettingUuid, PersonalAccessTokenNewValue::getAlmSettingKey).containsExactly(null, almPat.getAlmSettingUuid(), almSettingDto.getKey());
    assertThat(newValue.toString()).doesNotContain("userUuid");
}
Also used : PersonalAccessTokenNewValue(org.sonar.db.audit.model.PersonalAccessTokenNewValue) AlmPatsTesting.newAlmPatDto(org.sonar.db.alm.integration.pat.AlmPatsTesting.newAlmPatDto) AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) Test(org.junit.Test)

Example 3 with PersonalAccessTokenNewValue

use of org.sonar.db.audit.model.PersonalAccessTokenNewValue in project sonarqube by SonarSource.

the class AlmPatDaoWithPersisterTest method deleteByUserIsPersisted.

@Test
public void deleteByUserIsPersisted() {
    when(uuidFactory.create()).thenReturn(A_UUID);
    UserDto userDto = db.users().insertUser();
    AlmPatDto almPat = newAlmPatDto();
    almPat.setUserUuid(userDto.getUuid());
    underTest.insert(dbSession, almPat, userDto.getLogin(), null);
    verify(auditPersister).addPersonalAccessToken(eq(dbSession), newValueCaptor.capture());
    underTest.deleteByUser(dbSession, userDto);
    verify(auditPersister).deletePersonalAccessToken(eq(dbSession), newValueCaptor.capture());
    PersonalAccessTokenNewValue newValue = newValueCaptor.getValue();
    assertThat(newValue).extracting(PersonalAccessTokenNewValue::getPatUuid, PersonalAccessTokenNewValue::getUserUuid, PersonalAccessTokenNewValue::getUserLogin, PersonalAccessTokenNewValue::getAlmSettingKey).containsExactly(null, userDto.getUuid(), userDto.getLogin(), null);
    assertThat(newValue.toString()).doesNotContain("patUuid");
}
Also used : PersonalAccessTokenNewValue(org.sonar.db.audit.model.PersonalAccessTokenNewValue) UserDto(org.sonar.db.user.UserDto) AlmPatsTesting.newAlmPatDto(org.sonar.db.alm.integration.pat.AlmPatsTesting.newAlmPatDto) Test(org.junit.Test)

Example 4 with PersonalAccessTokenNewValue

use of org.sonar.db.audit.model.PersonalAccessTokenNewValue in project sonarqube by SonarSource.

the class AlmPatDao method insert.

public void insert(DbSession dbSession, AlmPatDto almPatDto, @Nullable String userLogin, @Nullable String almSettingKey) {
    String uuid = uuidFactory.create();
    long now = system2.now();
    almPatDto.setUuid(uuid);
    almPatDto.setCreatedAt(now);
    almPatDto.setUpdatedAt(now);
    getMapper(dbSession).insert(almPatDto);
    auditPersister.addPersonalAccessToken(dbSession, new PersonalAccessTokenNewValue(almPatDto, userLogin, almSettingKey));
}
Also used : PersonalAccessTokenNewValue(org.sonar.db.audit.model.PersonalAccessTokenNewValue)

Example 5 with PersonalAccessTokenNewValue

use of org.sonar.db.audit.model.PersonalAccessTokenNewValue in project sonarqube by SonarSource.

the class AlmPatDaoWithPersisterTest method deleteIsPersisted.

@Test
public void deleteIsPersisted() {
    when(uuidFactory.create()).thenReturn(A_UUID);
    AlmPatDto almPat = newAlmPatDto();
    underTest.insert(dbSession, almPat, null, null);
    verify(auditPersister).addPersonalAccessToken(eq(dbSession), newValueCaptor.capture());
    underTest.delete(dbSession, almPat, null, null);
    verify(auditPersister).deletePersonalAccessToken(eq(dbSession), newValueCaptor.capture());
    PersonalAccessTokenNewValue newValue = newValueCaptor.getValue();
    assertThat(newValue).extracting(PersonalAccessTokenNewValue::getPatUuid, PersonalAccessTokenNewValue::getUserUuid, PersonalAccessTokenNewValue::getAlmSettingUuid, PersonalAccessTokenNewValue::getUserLogin, PersonalAccessTokenNewValue::getAlmSettingKey).containsExactly(almPat.getUuid(), almPat.getUserUuid(), almPat.getAlmSettingUuid(), null, null);
    assertThat(newValue.toString()).doesNotContain("userLogin");
}
Also used : PersonalAccessTokenNewValue(org.sonar.db.audit.model.PersonalAccessTokenNewValue) AlmPatsTesting.newAlmPatDto(org.sonar.db.alm.integration.pat.AlmPatsTesting.newAlmPatDto) Test(org.junit.Test)

Aggregations

PersonalAccessTokenNewValue (org.sonar.db.audit.model.PersonalAccessTokenNewValue)6 Test (org.junit.Test)4 AlmPatsTesting.newAlmPatDto (org.sonar.db.alm.integration.pat.AlmPatsTesting.newAlmPatDto)4 AlmSettingDto (org.sonar.db.alm.setting.AlmSettingDto)1 UserDto (org.sonar.db.user.UserDto)1