|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2019 the original author or authors. |
| 2 | + * Copyright 2002-2020 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
23 | 23 | import org.springframework.security.oauth2.core.TestOAuth2AccessTokens;
|
24 | 24 | import org.springframework.security.oauth2.core.TestOAuth2RefreshTokens;
|
25 | 25 |
|
26 |
| -import static org.assertj.core.api.Assertions.*; |
| 26 | +import static org.assertj.core.api.Assertions.assertThat; |
| 27 | +import static org.assertj.core.api.Assertions.assertThatThrownBy; |
| 28 | +import static org.assertj.core.api.Assertions.entry; |
27 | 29 |
|
28 | 30 | /**
|
29 | 31 | * Tests for {@link OAuth2AuthorizeRequest}.
|
@@ -58,6 +60,13 @@ public void withClientRegistrationIdWhenPrincipalIsNullThenThrowIllegalArgumentE
|
58 | 60 | .hasMessage("principal cannot be null");
|
59 | 61 | }
|
60 | 62 |
|
| 63 | + @Test |
| 64 | + public void withClientRegistrationIdWhenPrincipalNameIsNullThenThrowIllegalArgumentException() { |
| 65 | + assertThatThrownBy(() -> OAuth2AuthorizeRequest.withClientRegistrationId(this.clientRegistration.getRegistrationId()).principal((String) null).build()) |
| 66 | + .isInstanceOf(IllegalArgumentException.class) |
| 67 | + .hasMessage("principalName cannot be empty"); |
| 68 | + } |
| 69 | + |
61 | 70 | @Test
|
62 | 71 | public void withClientRegistrationIdWhenAllValuesProvidedThenAllValuesAreSet() {
|
63 | 72 | OAuth2AuthorizeRequest authorizeRequest = OAuth2AuthorizeRequest.withClientRegistrationId(this.clientRegistration.getRegistrationId())
|
@@ -89,4 +98,15 @@ public void withAuthorizedClientWhenAllValuesProvidedThenAllValuesAreSet() {
|
89 | 98 | assertThat(authorizeRequest.getPrincipal()).isEqualTo(this.principal);
|
90 | 99 | assertThat(authorizeRequest.getAttributes()).contains(entry("name1", "value1"), entry("name2", "value2"));
|
91 | 100 | }
|
| 101 | + |
| 102 | + @Test |
| 103 | + public void withClientRegistrationIdWhenPrincipalNameProvidedThenPrincipalCreated() { |
| 104 | + OAuth2AuthorizeRequest authorizeRequest = OAuth2AuthorizeRequest.withClientRegistrationId(this.clientRegistration.getRegistrationId()) |
| 105 | + .principal("principalName") |
| 106 | + .build(); |
| 107 | + |
| 108 | + assertThat(authorizeRequest.getClientRegistrationId()).isEqualTo(this.clientRegistration.getRegistrationId()); |
| 109 | + assertThat(authorizeRequest.getAuthorizedClient()).isNull(); |
| 110 | + assertThat(authorizeRequest.getPrincipal().getName()).isEqualTo("principalName"); |
| 111 | + } |
92 | 112 | }
|
0 commit comments