Add client configuration settings
Closes gh-117
This commit is contained in:
@@ -322,6 +322,9 @@ public class RegisteredClientTests {
|
||||
RegisteredClient registration = TestRegisteredClients.registeredClient().build();
|
||||
RegisteredClient updated = RegisteredClient.withRegisteredClient(registration).build();
|
||||
|
||||
assertThat(registration.getId()).isEqualTo(updated.getId());
|
||||
assertThat(registration.getClientId()).isEqualTo(updated.getClientId());
|
||||
assertThat(registration.getClientSecret()).isEqualTo(updated.getClientSecret());
|
||||
assertThat(registration.getClientAuthenticationMethods()).isEqualTo(updated.getClientAuthenticationMethods());
|
||||
assertThat(registration.getClientAuthenticationMethods()).isNotSameAs(updated.getClientAuthenticationMethods());
|
||||
assertThat(registration.getAuthorizationGrantTypes()).isEqualTo(updated.getAuthorizationGrantTypes());
|
||||
@@ -330,20 +333,10 @@ public class RegisteredClientTests {
|
||||
assertThat(registration.getRedirectUris()).isNotSameAs(updated.getRedirectUris());
|
||||
assertThat(registration.getScopes()).isEqualTo(updated.getScopes());
|
||||
assertThat(registration.getScopes()).isNotSameAs(updated.getScopes());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void buildWhenRegisteredClientProvidedThenEachPropertyMatches() {
|
||||
RegisteredClient registration = TestRegisteredClients.registeredClient().build();
|
||||
RegisteredClient updated = RegisteredClient.withRegisteredClient(registration).build();
|
||||
|
||||
assertThat(registration.getId()).isEqualTo(updated.getId());
|
||||
assertThat(registration.getClientId()).isEqualTo(updated.getClientId());
|
||||
assertThat(registration.getClientSecret()).isEqualTo(updated.getClientSecret());
|
||||
assertThat(registration.getClientAuthenticationMethods()).isEqualTo(updated.getClientAuthenticationMethods());
|
||||
assertThat(registration.getAuthorizationGrantTypes()).isEqualTo(updated.getAuthorizationGrantTypes());
|
||||
assertThat(registration.getRedirectUris()).isEqualTo(updated.getRedirectUris());
|
||||
assertThat(registration.getScopes()).isEqualTo(updated.getScopes());
|
||||
assertThat(registration.getClientSettings().settings()).isEqualTo(updated.getClientSettings().settings());
|
||||
assertThat(registration.getClientSettings()).isNotSameAs(updated.getClientSettings());
|
||||
assertThat(registration.getTokenSettings().settings()).isEqualTo(updated.getTokenSettings().settings());
|
||||
assertThat(registration.getTokenSettings()).isNotSameAs(updated.getTokenSettings());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright 2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.security.oauth2.server.authorization.config;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
|
||||
/**
|
||||
* Tests for {@link ClientSettings}.
|
||||
*
|
||||
* @author Joe Grandja
|
||||
*/
|
||||
public class ClientSettingsTests {
|
||||
|
||||
@Test
|
||||
public void constructorWhenDefaultThenDefaultsAreSet() {
|
||||
ClientSettings clientSettings = new ClientSettings();
|
||||
assertThat(clientSettings.settings()).hasSize(1);
|
||||
assertThat(clientSettings.requireProofKey()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void constructorWhenNullThenThrowIllegalArgumentException() {
|
||||
assertThatThrownBy(() -> new ClientSettings(null))
|
||||
.isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessage("settings cannot be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void requireProofKeyWhenTrueThenSet() {
|
||||
ClientSettings clientSettings = new ClientSettings().requireProofKey(true);
|
||||
assertThat(clientSettings.requireProofKey()).isTrue();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Copyright 2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.security.oauth2.server.authorization.config;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.assertj.core.api.Assertions.entry;
|
||||
|
||||
/**
|
||||
* Tests for {@link Settings}.
|
||||
*
|
||||
* @author Joe Grandja
|
||||
*/
|
||||
public class SettingsTests {
|
||||
|
||||
@Test
|
||||
public void constructorWhenNullThenThrowIllegalArgumentException() {
|
||||
assertThatThrownBy(() -> new Settings(null))
|
||||
.isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessage("settings cannot be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void constructorWhenSettingsProvidedThenSettingsAreSet() {
|
||||
Map<String, Object> initialSettings = new HashMap<>();
|
||||
initialSettings.put("setting1", "value1");
|
||||
initialSettings.put("setting2", "value2");
|
||||
|
||||
Settings settings = new Settings(initialSettings)
|
||||
.setting("setting3", "value3")
|
||||
.settings(s -> s.put("setting4", "value4"));
|
||||
|
||||
assertThat(settings.settings()).contains(
|
||||
entry("setting1", "value1"),
|
||||
entry("setting2", "value2"),
|
||||
entry("setting3", "value3"),
|
||||
entry("setting4", "value4"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSettingWhenNameNullThenThrowIllegalArgumentException() {
|
||||
assertThatThrownBy(() -> new Settings().setting(null))
|
||||
.isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessage("name cannot be empty");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setSettingWhenNameNullThenThrowIllegalArgumentException() {
|
||||
assertThatThrownBy(() -> new Settings().setting(null, "value"))
|
||||
.isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessage("name cannot be empty");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setSettingWhenValueNullThenThrowIllegalArgumentException() {
|
||||
assertThatThrownBy(() -> new Settings().setting("setting", null))
|
||||
.isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessage("value cannot be null");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright 2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.security.oauth2.server.authorization.config;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
|
||||
/**
|
||||
* Tests for {@link TokenSettings}.
|
||||
*
|
||||
* @author Joe Grandja
|
||||
*/
|
||||
public class TokenSettingsTests {
|
||||
|
||||
@Test
|
||||
public void constructorWhenDefaultThenDefaultsAreSet() {
|
||||
TokenSettings tokenSettings = new TokenSettings();
|
||||
assertThat(tokenSettings.settings()).hasSize(1);
|
||||
assertThat(tokenSettings.accessTokenTimeToLive()).isEqualTo(Duration.ofMinutes(5));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void constructorWhenNullThenThrowIllegalArgumentException() {
|
||||
assertThatThrownBy(() -> new TokenSettings(null))
|
||||
.isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessage("settings cannot be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void accessTokenTimeToLiveWhenProvidedThenSet() {
|
||||
Duration accessTokenTimeToLive = Duration.ofMinutes(10);
|
||||
TokenSettings tokenSettings = new TokenSettings().accessTokenTimeToLive(accessTokenTimeToLive);
|
||||
assertThat(tokenSettings.accessTokenTimeToLive()).isEqualTo(accessTokenTimeToLive);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user