-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Tests for HttpServerOAuth2AuthTest
- Loading branch information
Showing
2 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
util/src/test/java/care/smith/fts/util/auth/HttpClientAuthTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package care.smith.fts.util.auth; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import care.smith.fts.util.auth.HttpClientAuth.Config; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class HttpClientAuthTest { | ||
|
||
HttpClientBasicAuth.Config basic = new HttpClientBasicAuth.Config("username", "password"); | ||
HttpClientOAuth2Auth.Config oauth2 = new HttpClientOAuth2Auth.Config("registration"); | ||
HttpClientCookieTokenAuth.Config cookieToken = new HttpClientCookieTokenAuth.Config("cookie"); | ||
|
||
@Test | ||
void full_constructor() { | ||
var config = new Config(basic, oauth2, cookieToken); | ||
assertThat(config.basic()).isNotNull(); | ||
assertThat(config.oauth2()).isNotNull(); | ||
assertThat(config.cookieToken()).isNotNull(); | ||
} | ||
|
||
@Test | ||
void basic_constructor() { | ||
var config = new Config(basic); | ||
assertThat(config.basic()).isNotNull(); | ||
assertThat(config.oauth2()).isNull(); | ||
assertThat(config.cookieToken()).isNull(); | ||
} | ||
|
||
@Test | ||
void oauth2_constructor() { | ||
var config = new Config(oauth2); | ||
assertThat(config.basic()).isNull(); | ||
assertThat(config.oauth2()).isNotNull(); | ||
assertThat(config.cookieToken()).isNull(); | ||
} | ||
|
||
@Test | ||
void cookie_constructor() { | ||
var config = new Config(cookieToken); | ||
assertThat(config.basic()).isNull(); | ||
assertThat(config.oauth2()).isNull(); | ||
assertThat(config.cookieToken()).isNotNull(); | ||
} | ||
|
||
@Test | ||
void basic_oauth2_constructor() { | ||
var config = new Config(basic, oauth2); | ||
assertThat(config.basic()).isNotNull(); | ||
assertThat(config.oauth2()).isNotNull(); | ||
assertThat(config.cookieToken()).isNull(); | ||
} | ||
|
||
@Test | ||
void basic_cookie_constructor() { | ||
var config = new Config(basic, cookieToken); | ||
assertThat(config.basic()).isNotNull(); | ||
assertThat(config.oauth2()).isNull(); | ||
assertThat(config.cookieToken()).isNotNull(); | ||
} | ||
|
||
@Test | ||
void oauth2_cookie_constructor() { | ||
var config = new Config(oauth2, cookieToken); | ||
assertThat(config.basic()).isNull(); | ||
assertThat(config.oauth2()).isNotNull(); | ||
assertThat(config.cookieToken()).isNotNull(); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
util/src/test/java/care/smith/fts/util/auth/HttpServerOAuth2AuthTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package care.smith.fts.util.auth; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.springframework.security.access.SecurityConfig; | ||
import org.springframework.security.config.web.server.ServerHttpSecurity; | ||
import org.springframework.security.web.server.SecurityWebFilterChain; | ||
import org.springframework.security.web.server.authentication.AuthenticationWebFilter; | ||
import org.springframework.security.web.server.util.matcher.ServerWebExchangeMatcher; | ||
|
||
class HttpServerOAuth2AuthTest { | ||
HttpServerOAuth2Auth auth = new HttpServerOAuth2Auth("issuer", "clientId"); | ||
|
||
@Test | ||
void configure() { | ||
var security = ServerHttpSecurity.http(); | ||
var result = auth.configure(security).build(); | ||
|
||
assertThat(result.getWebFilters().collectList().block()) | ||
.filteredOn(filter -> filter instanceof AuthenticationWebFilter) | ||
.hasSize(1); | ||
} | ||
|
||
@Test | ||
void configureUsers() { | ||
assertThat(auth.configureUsers()).isNull(); | ||
} | ||
|
||
@Test | ||
void testToString() { | ||
assertThat(auth.toString()).isEqualTo("OAuth2"); | ||
} | ||
} |