@Test public void genSaltGeneratesCorrectSaltPrefix() { assertThat(BCrypt.gensalt(4)).startsWith("$2a$04$"); assertThat(BCrypt.gensalt(31)).startsWith("$2a$31$"); }
@Test public void shouldGenerateEncryptedText() throws CryptoException { String encrypt = aesEncrypter.encrypt("p@ssw0rd"); assertThat(encrypt).startsWith("AES"); assertThat(encrypt.split(":")).hasSize(3); }
@Test public void successIsLoggedIfAceRequiresSuccessAudit() throws Exception { when(ace.isAuditSuccess()).thenReturn(true); logger.logIfNeeded(true, ace); assertThat(bytes.toString()).startsWith("GRANTED due to ACE"); }
@Test public void debug2() throws Exception { logger.debug("with cause", CAUSE); assertThat(errContent.size()).isZero(); assertThat(outContent.toString()) .startsWith("[DEBUG] (" + Thread.currentThread().getName() + ") with cause - java.lang.IllegalStateException: cause" + "\njava.lang.IllegalStateException: cause\n" + "\tat reactor.util.ConsoleLoggerTest"); }
@Test public void info2() throws Exception { logger.info("with cause", CAUSE); assertThat(errContent.size()).isZero(); assertThat(outContent.toString()) .startsWith("[ INFO] (" + Thread.currentThread().getName() + ") with cause - java.lang.IllegalStateException: cause" + "\njava.lang.IllegalStateException: cause\n" + "\tat reactor.util.ConsoleLoggerTest"); }
@Test public void failureIsLoggedIfAceRequiresFailureAudit() throws Exception { when(ace.isAuditFailure()).thenReturn(true); logger.logIfNeeded(false, ace); assertThat(bytes.toString()).startsWith("DENIED due to ACE"); } }
@Test public void encodeWhenDefaultThenBCryptUsed() { String encodedPassword = this.encoder.encode(this.rawPassword); assertThat(encodedPassword).startsWith("{bcrypt}"); assertThat(this.encoder.matches(this.rawPassword, encodedPassword)).isTrue(); }
@Test public void shouldReturnBoltUrl() { String actual = neo4jContainer.getBoltUrl(); assertThat(actual).isNotNull(); assertThat(actual).startsWith("bolt://"); }
@Test public void shouldReturnHttpUrl() { String actual = neo4jContainer.getHttpUrl(); assertThat(actual).isNotNull(); assertThat(actual).startsWith("http://"); } }
@Test public void stepNameAndToString() { AssemblySnapshot stacktrace = new AssemblySnapshot(null, Traces.callSiteSupplierFactory.get()); MonoCallableOnAssembly<?> test = new MonoCallableOnAssembly<>(Mono.empty(), stacktrace); assertThat(test.toString()) .isEqualTo(test.stepName()) .startsWith("reactor.core.publisher.MonoCallableOnAssemblyTest.stepNameAndToString(MonoCallableOnAssemblyTest.java:"); }
@Test public void stepNameAndToString() { AssemblySnapshot stacktrace = new AssemblySnapshot(null, Traces.callSiteSupplierFactory.get()); MonoOnAssembly<?> test = new MonoOnAssembly<>(Mono.empty(), stacktrace); assertThat(test.toString()) .isEqualTo(test.stepName()) .startsWith("reactor.core.publisher.MonoOnAssemblyTest.stepNameAndToString(MonoOnAssemblyTest.java:"); }
@Test public void stepNameAndToString() { AssemblySnapshot stacktrace = new AssemblySnapshot(null, Traces.callSiteSupplierFactory.get()); FluxCallableOnAssembly<?> test = new FluxCallableOnAssembly<>(Flux.empty(), stacktrace); assertThat(test.toString()) .isEqualTo(test.stepName()) .startsWith("reactor.core.publisher.FluxCallableOnAssemblyTest.stepNameAndToString(FluxCallableOnAssemblyTest.java:"); } }
@Test public void shouldConvertFromDESEncryptedTextToAES() throws IOException, CryptoException { resetCipher.setupAESCipherFile(); resetCipher.setupDESCipherFile(); GoCipher goCipher = new GoCipher(systemEnvironment); String cipherText = goCipher.desToAES("mvcX9yrQsM4iPgm1tDxN1A=="); assertThat(cipherText).startsWith("AES:"); } }
@Test public void stepNameAndToString() { AssemblySnapshot stacktrace = new AssemblySnapshot(null, Traces.callSiteSupplierFactory.get()); ConnectableFluxOnAssembly<?> test = new ConnectableFluxOnAssembly<>(Flux.empty().publish(), stacktrace); assertThat(test.toString()) .isEqualTo(test.stepName()) .startsWith("reactor.core.publisher.ConnectableFluxOnAssemblyTest.stepNameAndToString(ConnectableFluxOnAssemblyTest.java:"); }
@Test public void stepNameAndToString() { ParallelFlux<Integer> source = Flux.range(1, 4).parallel(3); AssemblySnapshot stacktrace = new AssemblySnapshot("foo", Traces.callSiteSupplierFactory.get()); ParallelFluxOnAssembly<Integer> test = new ParallelFluxOnAssembly<>(source, stacktrace); assertThat(test.toString()) .isEqualTo(test.stepName()) .startsWith("reactor.core.publisher.ParallelFluxOnAssemblyTest.stepNameAndToString(ParallelFluxOnAssemblyTest.java:"); }
@Test public void getTokenResponseWhenClientAuthenticationBasicThenAuthorizationHeaderIsSent() throws Exception { String accessTokenSuccessResponse = "{\n" + " \"access_token\": \"access-token-1234\",\n" + " \"token_type\": \"bearer\",\n" + " \"expires_in\": \"3600\"\n" + "}\n"; this.server.enqueue(jsonResponse(accessTokenSuccessResponse)); this.tokenResponseClient.getTokenResponse(this.authorizationCodeGrantRequest()); RecordedRequest recordedRequest = this.server.takeRequest(); assertThat(recordedRequest.getHeader(HttpHeaders.AUTHORIZATION)).startsWith("Basic "); }
@Test public void defaultLoginPageWithSingleClientRegistrationThenRedirect() { this.spring.register(OAuth2LoginWithSingleClientRegistrations.class).autowire(); WebTestClient webTestClient = WebTestClientBuilder .bindToWebFilters(new GitHubWebFilter(), this.springSecurity) .build(); WebDriver driver = WebTestClientHtmlUnitDriverBuilder .webTestClientSetup(webTestClient) .build(); driver.get("http://localhost/"); assertThat(driver.getCurrentUrl()).startsWith("https://github.com/login/oauth/authorize"); }
@Test public void loadConfigWhenInMemoryConfigureGlobalThenPasswordUpgraded() throws Exception { this.spring.register(InMemoryConfigureGlobalConfig.class).autowire(); this.mockMvc.perform(formLogin()) .andExpect(status().is3xxRedirection()); UserDetailsService uds = this.spring.getContext() .getBean(UserDetailsService.class); assertThat(uds.loadUserByUsername("user").getPassword()).startsWith("{bcrypt}"); }
@Test public void loadConfigWhenInMemoryConfigureProtectedThenPasswordUpgraded() throws Exception { this.spring.register(InMemoryConfigureProtectedConfig.class).autowire(); this.mockMvc.perform(formLogin()) .andExpect(status().is3xxRedirection()); UserDetailsService uds = this.spring.getContext() .getBean(UserDetailsService.class); assertThat(uds.loadUserByUsername("user").getPassword()).startsWith("{bcrypt}"); }
@Test public void passwordUpdateManagerUsed() { this.spring.register(MapReactiveUserDetailsServiceConfig.class).autowire(); WebTestClient client = WebTestClientBuilder.bindToWebFilters(this.springSecurityFilterChain).build(); client .get() .uri("/") .headers(h -> h.setBasicAuth("user", "password")) .exchange() .expectStatus().isOk(); ReactiveUserDetailsService users = this.spring.getContext().getBean(ReactiveUserDetailsService.class); assertThat(users.findByUsername("user").block().getPassword()).startsWith("{bcrypt}"); }