import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.project.ProjectDto;
+import org.sonar.db.scim.ScimUserDto;
import static java.util.Arrays.asList;
import static java.util.Collections.emptyList;
List<UserTelemetryDto> result = underTest.selectUsersForTelemetry(db.getSession());
assertThat(result)
- .extracting(UserTelemetryDto::getUuid, UserTelemetryDto::isActive, UserTelemetryDto::getLastConnectionDate, UserTelemetryDto::getLastSonarlintConnectionDate)
+ .extracting(UserTelemetryDto::getUuid, UserTelemetryDto::isActive, UserTelemetryDto::getLastConnectionDate, UserTelemetryDto::getLastSonarlintConnectionDate, UserTelemetryDto::getScimUuid)
.containsExactlyInAnyOrder(
- tuple(u1.getUuid(), u1.isActive(), u1.getLastConnectionDate(), u1.getLastSonarlintConnectionDate()),
- tuple(u2.getUuid(), u2.isActive(), u2.getLastConnectionDate(), u2.getLastSonarlintConnectionDate()));
+ tuple(u1.getUuid(), u1.isActive(), u1.getLastConnectionDate(), u1.getLastSonarlintConnectionDate(), null),
+ tuple(u2.getUuid(), u2.isActive(), u2.getLastConnectionDate(), u2.getLastSonarlintConnectionDate(), null)
+ );
}
@Test
tuple(u2.getUuid(), u2.isActive(), 20_000_000_000L, u2.getLastSonarlintConnectionDate()));
}
+ @Test
+ public void selectUserTelemetryWithScim() {
+ UserDto u1 = insertUser(true);
+ UserDto u2 = insertUser(false);
+ ScimUserDto scimUser1 = enableScimForUser(u1);
+
+ List<UserTelemetryDto> result = underTest.selectUsersForTelemetry(db.getSession());
+
+ assertThat(result)
+ .extracting(UserTelemetryDto::getUuid, UserTelemetryDto::isActive, UserTelemetryDto::getLastConnectionDate, UserTelemetryDto::getLastSonarlintConnectionDate, UserTelemetryDto::getScimUuid)
+ .containsExactlyInAnyOrder(
+ tuple(u1.getUuid(), u1.isActive(), u1.getLastConnectionDate(), u1.getLastSonarlintConnectionDate(), scimUser1.getScimUserUuid()),
+ tuple(u2.getUuid(), u2.isActive(), u2.getLastConnectionDate(), u2.getLastSonarlintConnectionDate(), null)
+ );
+ }
+
private UserDto insertActiveUser() {
return insertUser(true);
}
return dto;
}
+
+ private ScimUserDto enableScimForUser(UserDto userDto) {
+ return dbClient.scimUserDao().enableScimForUser(db.getSession(), userDto.getUuid());
+ }
+
private UserGroupDto insertUserGroup(UserDto user) {
GroupDto group = newGroupDto().setName(randomAlphanumeric(30));
dbClient.groupDao().insert(session, group);
"status": "active",
"identityProvider": "gitlab",
"lastActivity": "1970-01-01T00:00:00+0000",
- "lastSonarlintActivity": "1970-01-01T00:00:00+0000"
+ "lastSonarlintActivity": "1970-01-01T00:00:00+0000",
+ "managed": true
},
{
"userUuid": "%s",
"status": "inactive",
"identityProvider": "gitlab",
"lastActivity": "1970-01-01T00:00:00+0000",
- "lastSonarlintActivity": "1970-01-01T00:00:00+0000"
+ "lastSonarlintActivity": "1970-01-01T00:00:00+0000",
+ "managed": false
},
{
"userUuid": "%s",
"status": "active",
"identityProvider": "gitlab",
"lastActivity": "1970-01-01T00:00:00+0000",
- "lastSonarlintActivity": "1970-01-01T00:00:00+0000"
+ "lastSonarlintActivity": "1970-01-01T00:00:00+0000",
+ "managed": true
}
]
}
private static List<UserTelemetryDto> attachUsers() {
return IntStream.range(0, 3)
.mapToObj(
- i -> new UserTelemetryDto().setUuid("uuid-" + i).setActive(i % 2 == 0).setLastConnectionDate(1L).setLastSonarlintConnectionDate(2L).setExternalIdentityProvider("gitlab"))
+ i -> new UserTelemetryDto().setUuid("uuid-" + i).setActive(i % 2 == 0).setLastConnectionDate(1L)
+ .setLastSonarlintConnectionDate(2L).setExternalIdentityProvider("gitlab").setScimUuid(i % 2 == 0 ? "scim-uuid-" + i : null))
.collect(Collectors.toList());
}