use of org.cloudfoundry.identity.uaa.util.TimeServiceImpl in project uaa by cloudfoundry.
the class UaaMetricsFilterTests method intolerable_request.
@Test
void intolerable_request() throws Exception {
TimeService slowRequestTimeService = new TimeService() {
long now = System.currentTimeMillis();
@Override
public long getCurrentTimeMillis() {
now += 5000;
return now;
}
};
for (TimeService timeService : Arrays.asList(slowRequestTimeService, new TimeServiceImpl())) {
reset(publisher);
filter = new UaaMetricsFilter(true, true, timeService);
filter.setNotificationPublisher(publisher);
String path = "/authenticate/test";
setRequestData(path);
filter.getUriGroup(request).setLimit(1000);
filter.doFilterInternal(request, response, chain);
MetricsQueue metricsQueue = filter.getMetricsQueue(filter.getUriGroup(request).getGroup());
RequestMetricSummary totals = metricsQueue.getTotals();
assertEquals(1, totals.getCount());
assertEquals(timeService == slowRequestTimeService ? 1 : 0, totals.getIntolerableCount());
ArgumentCaptor<Notification> argumentCaptor = ArgumentCaptor.forClass(Notification.class);
verify(publisher).sendNotification(argumentCaptor.capture());
Notification capturedArg = argumentCaptor.getValue();
assertEquals("/api", capturedArg.getType());
}
}
use of org.cloudfoundry.identity.uaa.util.TimeServiceImpl in project uaa by cloudfoundry.
the class UaaMetricsFilterTests method idle_counter.
@Test
void idle_counter() throws Exception {
IdleTimer mockIdleTimer = mock(IdleTimer.class);
setRequestData("/oauth/token");
final FilterChain chain = mock(FilterChain.class);
final UaaMetricsFilter filter = new UaaMetricsFilter(true, false, new TimeServiceImpl());
ReflectionTestUtils.setField(filter, "inflight", mockIdleTimer);
filter.doFilterInternal(request, response, chain);
verify(chain, times(1)).doFilter(same(request), same(response));
verify(mockIdleTimer, times(1)).startRequest();
verify(mockIdleTimer, times(1)).endRequest();
}
use of org.cloudfoundry.identity.uaa.util.TimeServiceImpl in project uaa by cloudfoundry.
the class UaaMetricsFilterTests method happy_path.
@Test
void happy_path() throws Exception {
filter = spy(new UaaMetricsFilter(true, true, new TimeServiceImpl()));
filter.setNotificationPublisher(publisher);
String path = performTwoSimpleRequests();
Map<String, String> summary = filter.getSummary();
assertNotNull(summary);
assertFalse(summary.isEmpty());
assertEquals(2, summary.size());
for (String uri : Arrays.asList(path, MetricsUtil.GLOBAL_GROUP)) {
MetricsQueue totals = readValue(summary.get(filter.getUriGroup(request).getGroup()), MetricsQueue.class);
assertNotNull(totals, "URI:" + uri);
for (StatusCodeGroup status : Arrays.asList(StatusCodeGroup.SUCCESS, StatusCodeGroup.SERVER_ERROR)) {
RequestMetricSummary total = totals.getDetailed().get(status);
assertEquals(1, total.getCount(), "URI:" + uri);
}
}
assertNull(MetricsAccessor.getCurrent());
ArgumentCaptor<Notification> argumentCaptor = ArgumentCaptor.forClass(Notification.class);
verify(publisher, times(2)).sendNotification(argumentCaptor.capture());
List<Notification> capturedArg = argumentCaptor.getAllValues();
assertEquals(2, capturedArg.size());
assertEquals("/api", capturedArg.get(0).getType());
}
use of org.cloudfoundry.identity.uaa.util.TimeServiceImpl in project uaa by cloudfoundry.
the class JdbcScimGroupMembershipManagerTests method setUp.
@BeforeEach
void setUp() {
generator = new RandomValueStringGenerator();
otherIdentityZone = MultitenancyFixture.identityZone("otherIdentityZone-" + generator.generate(), "otherIdentityZone-" + generator.generate());
uaaIdentityZone = IdentityZone.getUaa();
JdbcPagingListFactory pagingListFactory = new JdbcPagingListFactory(jdbcTemplate, limitSqlAdapter);
JdbcScimUserProvisioning jdbcScimUserProvisioning = new JdbcScimUserProvisioning(jdbcTemplate, pagingListFactory, passwordEncoder);
jdbcScimGroupProvisioning = new JdbcScimGroupProvisioning(jdbcTemplate, pagingListFactory);
jdbcScimGroupMembershipManager = new JdbcScimGroupMembershipManager(jdbcTemplate, new TimeServiceImpl(), jdbcScimUserProvisioning, null);
jdbcScimGroupMembershipManager.setScimGroupProvisioning(jdbcScimGroupProvisioning);
IdentityZoneHolder.get().getConfig().getUserConfig().setDefaultGroups(Collections.singletonList("uaa.user"));
jdbcScimGroupProvisioning.createOrGet(new ScimGroup(null, "uaa.user", IdentityZoneHolder.get().getId()), IdentityZoneHolder.get().getId());
addUsersAndGroups(jdbcTemplate, otherIdentityZone.getId(), otherIdentityZone.getId() + "-");
addUsersAndGroups(jdbcTemplate, uaaIdentityZone.getId(), "");
validateCount(0, jdbcTemplate, IdentityZoneHolder.get().getId());
}
use of org.cloudfoundry.identity.uaa.util.TimeServiceImpl in project uaa by cloudfoundry.
the class JdbcScimGroupProvisioningTests method initJdbcScimGroupProvisioningTests.
@BeforeEach
void initJdbcScimGroupProvisioningTests() {
generator = new RandomValueStringGenerator();
SecureRandom random = new SecureRandom();
random.setSeed(System.nanoTime());
generator.setRandom(random);
zoneId = generator.generate();
IdentityZone zone = new IdentityZone();
zone.setId(zoneId);
IdentityZoneHolder.set(zone);
IdentityZoneHolder.get().getConfig().getUserConfig().setDefaultGroups(new ArrayList<>());
validateGroupCountInZone(0, zoneId);
dao = spy(new JdbcScimGroupProvisioning(jdbcTemplate, new JdbcPagingListFactory(jdbcTemplate, limitSqlAdapter)));
users = mock(ScimUserProvisioning.class);
memberships = new JdbcScimGroupMembershipManager(jdbcTemplate, new TimeServiceImpl(), users, null);
memberships.setScimGroupProvisioning(dao);
dao.setJdbcScimGroupMembershipManager(memberships);
JdbcScimGroupExternalMembershipManager jdbcScimGroupExternalMembershipManager = new JdbcScimGroupExternalMembershipManager(jdbcTemplate);
jdbcScimGroupExternalMembershipManager.setScimGroupProvisioning(dao);
dao.setJdbcScimGroupExternalMembershipManager(jdbcScimGroupExternalMembershipManager);
g1Id = "g1";
g2Id = "g2";
g3Id = "g3";
group1Description = "u" + generator.generate();
g1 = addGroup(g1Id, group1Description, zoneId);
group2Description = "u" + generator.generate();
g2 = addGroup(g2Id, group2Description, zoneId);
group3Description = "op" + generator.generate();
g3 = addGroup(g3Id, group3Description, zoneId);
validateGroupCountInZone(3, zoneId);
}
Aggregations