Refine search
private void verifyCallActiveRuleIndexerDelete(String... expectedRuleProfileUuids) { Class<Set<QProfileDto>> setClass = (Class<Set<QProfileDto>>) (Class) Set.class; ArgumentCaptor<Set<QProfileDto>> setCaptor = ArgumentCaptor.forClass(setClass); verify(activeRuleIndexer).commitDeletionOfProfiles(any(DbSession.class), setCaptor.capture()); assertThat(setCaptor.getValue()) .extracting(QProfileDto::getKee) .containsExactlyInAnyOrder(expectedRuleProfileUuids); }
@Test public void validateWhenIssuedAt1minAheadAnd0minClockSkewThenHasErrors() { this.issuedAt = Instant.now().plus(Duration.ofMinutes(1)); this.expiresAt = this.issuedAt.plus(Duration.ofSeconds(60)); this.clockSkew = Duration.ofMinutes(0); assertThat(this.validateIdToken()) .hasSize(1) .extracting(OAuth2Error::getDescription) .allMatch(msg -> msg.contains(IdTokenClaimNames.IAT)); }
@Test public void validateWhenMultipleAudAzpNotClientIdThenHasErrors() { this.claims.put(IdTokenClaimNames.AUD, Arrays.asList("client-id-1", "client-id-2")); this.claims.put(IdTokenClaimNames.AZP, "other-client"); assertThat(this.validateIdToken()) .hasSize(1) .extracting(OAuth2Error::getDescription) .allMatch(msg -> msg.contains(IdTokenClaimNames.AZP)); }
private void verifyDescendants(Collection<QProfileDto> baseProfiles, Collection<QProfileDto> expectedDescendants) { Collection<QProfileDto> descendants = underTest.selectDescendants(dbSession, baseProfiles); String[] expectedUuids = expectedDescendants.stream().map(QProfileDto::getKee).toArray(String[]::new); assertThat(descendants) .extracting(QProfileDto::getKee) .containsExactlyInAnyOrder(expectedUuids); }
@Test public void validateWhenAudNotClientIdThenHasErrors() { this.claims.put(IdTokenClaimNames.AUD, Collections.singletonList("other-client")); assertThat(this.validateIdToken()) .hasSize(1) .extracting(OAuth2Error::getDescription) .allMatch(msg -> msg.contains(IdTokenClaimNames.AUD)); }
private void assertResult(String componentKey, String branch, Tuple... tuples) { try (CloseableIterator<ServerIssue> result = callStream(componentKey, branch)) { assertThat(result) .extracting(ServerIssue::getKey, ServerIssue::getModuleKey) .containsExactlyInAnyOrder(tuples); } }
@Test public void findAll_returns_all_rules_when_RuleQuery_has_no_non_null_field() { assertThat(underTest.findAll(RuleQuery.create())) .extracting(CachingRuleFinderTest::toRuleKey) .containsOnly(Arrays.stream(ruleDefinitions).map(RuleDefinitionDto::getKey).toArray(RuleKey[]::new)); }
private void verifyListenerCalled(QGChangeEventListener listener, QGChangeEvent changeEvent, DefaultIssue... issues) { ArgumentCaptor<Set<ChangedIssue>> changedIssuesCaptor = newSetCaptor(); verify(listener).onIssueChanges(same(changeEvent), changedIssuesCaptor.capture()); Set<ChangedIssue> changedIssues = changedIssuesCaptor.getValue(); Tuple[] expected = Arrays.stream(issues) .map(issue -> tuple(issue.key(), ChangedIssueImpl.statusOf(issue), issue.type())) .toArray(Tuple[]::new); assertThat(changedIssues) .hasSize(issues.length) .extracting(ChangedIssue::getKey, t -> t.getStatus(), ChangedIssue::getType) .containsOnly(expected); }
@Test public void validateWhenAudMultipleAndAzpNullThenHasErrors() { this.claims.put(IdTokenClaimNames.AUD, Arrays.asList("client-id", "other")); assertThat(this.validateIdToken()) .hasSize(1) .extracting(OAuth2Error::getDescription) .allMatch(msg -> msg.contains(IdTokenClaimNames.AZP)); }
private void assertCondition(QualityGateDto qualityGate, MetricDto metric, String operator, String error) { assertThat(dbClient.gateConditionDao().selectForQualityGate(dbSession, qualityGate.getId())) .extracting(QualityGateConditionDto::getQualityGateId, QualityGateConditionDto::getMetricId, QualityGateConditionDto::getOperator, QualityGateConditionDto::getErrorThreshold) .containsExactlyInAnyOrder(tuple(qualityGate.getId(), metric.getId().longValue(), operator, error)); }
@Test public void validateWhenSubNullThenHasErrors() { this.claims.remove(IdTokenClaimNames.SUB); assertThat(this.validateIdToken()) .hasSize(1) .extracting(OAuth2Error::getDescription) .allMatch(msg -> msg.contains(IdTokenClaimNames.SUB)); }
private void assertCondition(QualityGateDto qualityGate, MetricDto metric, String operator, String error) { assertThat(dbClient.gateConditionDao().selectForQualityGate(dbSession, qualityGate.getId())) .extracting(QualityGateConditionDto::getQualityGateId, QualityGateConditionDto::getMetricId, QualityGateConditionDto::getOperator, QualityGateConditionDto::getErrorThreshold) .containsExactlyInAnyOrder(tuple(qualityGate.getId(), metric.getId().longValue(), operator, error)); }
@Test public void validateWhenExpiredAnd0secClockSkewThenHasErrors() { this.issuedAt = Instant.now().minus(Duration.ofSeconds(60)); this.expiresAt = this.issuedAt.plus(Duration.ofSeconds(30)); this.clockSkew = Duration.ofSeconds(0); assertThat(this.validateIdToken()) .hasSize(1) .extracting(OAuth2Error::getDescription) .allMatch(msg -> msg.contains(IdTokenClaimNames.EXP)); }
private void verifyContentOfPreloadedSearchResponseData(IssueDto issue) { SearchResponseData preloadedSearchResponseData = preloadedSearchResponseDataCaptor.getValue(); assertThat(preloadedSearchResponseData.getIssues()) .extracting(IssueDto::getKey) .containsOnly(issue.getKey()); assertThat(preloadedSearchResponseData.getRules()) .extracting(RuleDefinitionDto::getKey) .containsOnly(issue.getRuleKey()); assertThat(preloadedSearchResponseData.getComponents()) .extracting(ComponentDto::uuid) .containsOnly(issue.getComponentUuid(), issue.getProjectUuid()); }
@Test public void getAuthenticationManagerWhenProtectedPasswordEncoderBeanThenUsed() throws Exception { this.spring.register(PasswordEncoderGlobalConfig.class).autowire(); AuthenticationManager manager = this.spring.getContext() .getBean(AuthenticationConfiguration.class).getAuthenticationManager(); Authentication auth = manager.authenticate(new UsernamePasswordAuthenticationToken("user", "password")); assertThat(auth.getName()).isEqualTo("user"); assertThat(auth.getAuthorities()).extracting(GrantedAuthority::getAuthority).containsOnly("ROLE_USER"); }
private void verifyContentOfPreloadedSearchResponseData(IssueDto issue) { SearchResponseData preloadedSearchResponseData = preloadedSearchResponseDataCaptor.getValue(); assertThat(preloadedSearchResponseData.getIssues()) .extracting(IssueDto::getKey) .containsOnly(issue.getKey()); assertThat(preloadedSearchResponseData.getRules()) .extracting(RuleDefinitionDto::getKey) .containsOnly(issue.getRuleKey()); assertThat(preloadedSearchResponseData.getComponents()) .extracting(ComponentDto::uuid) .containsOnly(issue.getComponentUuid(), issue.getProjectUuid()); }
@Test public void validateWhenAudNullThenHasErrors() { this.claims.remove(IdTokenClaimNames.AUD); assertThat(this.validateIdToken()) .hasSize(1) .extracting(OAuth2Error::getDescription) .allMatch(msg -> msg.contains(IdTokenClaimNames.AUD)); }
@Test public void validateWhenExpiresAtBeforeNowThenHasErrors() { this.issuedAt = Instant.now().minus(Duration.ofSeconds(10)); this.expiresAt = this.issuedAt.plus(Duration.ofSeconds(5)); this.clockSkew = Duration.ofSeconds(0); assertThat(this.validateIdToken()) .hasSize(1) .extracting(OAuth2Error::getDescription) .allMatch(msg -> msg.contains(IdTokenClaimNames.EXP)); }
@Test public void list_uninstalled_plugins() throws IOException { new File(uninstallDir, "file1").createNewFile(); copyTestPluginTo("test-base-plugin", uninstallDir); assertThat(underTest.getUninstalledPlugins()).extracting("key").containsOnly("testbase"); }
@Test public void getAuthenticationManagerWhenGlobalPasswordEncoderBeanThenUsed() throws Exception { this.spring.register(PasswordEncoderGlobalConfig.class).autowire(); AuthenticationManager manager = this.spring.getContext() .getBean(AuthenticationConfiguration.class).getAuthenticationManager(); Authentication auth = manager.authenticate(new UsernamePasswordAuthenticationToken("user", "password")); assertThat(auth.getName()).isEqualTo("user"); assertThat(auth.getAuthorities()).extracting(GrantedAuthority::getAuthority).containsOnly("ROLE_USER"); }