This repository has been archived by the owner on Sep 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
'clientCredentialsProvider' merged into master
- Loading branch information
Showing
6 changed files
with
217 additions
and
12 deletions.
There are no files selected for viewing
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
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
84 changes: 84 additions & 0 deletions
84
...-boot-zalando-stups-tokens/src/test/java/com/unknown/pkg/ClientCredentialsProviderIT.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,84 @@ | ||
/** | ||
* Copyright (C) 2015 Zalando SE (http://tech.zalando.com) | ||
* | ||
* 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 | ||
* | ||
* http://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 com.unknown.pkg; | ||
|
||
import java.util.List; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import org.assertj.core.api.Assertions; | ||
|
||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
|
||
import org.junit.runner.RunWith; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
import org.springframework.boot.test.SpringApplicationConfiguration; | ||
import org.springframework.boot.test.WebIntegrationTest; | ||
|
||
import org.springframework.test.context.ActiveProfiles; | ||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; | ||
|
||
import org.zalando.stups.tokens.AccessToken; | ||
import org.zalando.stups.tokens.AccessTokens; | ||
import org.zalando.stups.tokens.AccessTokensBean; | ||
import org.zalando.stups.tokens.ClientCredentialsProvider; | ||
import org.zalando.stups.tokens.config.AccessTokensBeanProperties; | ||
import org.zalando.stups.tokens.config.TokenConfiguration; | ||
|
||
import com.google.common.base.Predicate; | ||
import com.google.common.collect.Iterables; | ||
|
||
/** | ||
* @author jbellmann | ||
*/ | ||
@RunWith(SpringJUnit4ClassRunner.class) | ||
@SpringApplicationConfiguration(classes = {TokenTestApplication.class}) | ||
@WebIntegrationTest(randomPort = false) | ||
@ActiveProfiles("exposeClient") | ||
public class ClientCredentialsProviderIT { | ||
|
||
static final String OAUTH2_ACCESS_TOKENS = "OAUTH2_ACCESS_TOKENS"; | ||
|
||
@Autowired | ||
private AccessTokensBean tokens; | ||
|
||
@Autowired | ||
private AccessTokensBeanProperties accessTokensBeanProperties; | ||
|
||
@Autowired | ||
private AccessTokens accessTokens; | ||
|
||
@Autowired | ||
private ClientCredentialsProvider clientCredentialsProvider; | ||
|
||
@BeforeClass | ||
public static void setUp() { | ||
System.getProperties().remove(OAUTH2_ACCESS_TOKENS); | ||
} | ||
|
||
@Test | ||
public void testClientCredentialProviderIsPresent() throws InterruptedException { | ||
Assertions.assertThat(clientCredentialsProvider).isNotNull(); | ||
String clientId = clientCredentialsProvider.get().getId(); | ||
Assertions.assertThat(clientId).isNotNull(); | ||
Assertions.assertThat(clientId).isEqualTo("foo"); | ||
String clientSecret = clientCredentialsProvider.get().getSecret(); | ||
Assertions.assertThat(clientSecret).isNotNull(); | ||
Assertions.assertThat(clientSecret).isEqualTo("bar"); | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
...-zalando-stups-tokens/src/test/java/com/unknown/pkg/DoNotClientCredentialsProviderIT.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 @@ | ||
/** | ||
* Copyright (C) 2015 Zalando SE (http://tech.zalando.com) | ||
* | ||
* 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 | ||
* | ||
* http://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 com.unknown.pkg; | ||
|
||
import java.util.List; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import org.assertj.core.api.Assertions; | ||
|
||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
|
||
import org.junit.runner.RunWith; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
import org.springframework.boot.test.SpringApplicationConfiguration; | ||
import org.springframework.boot.test.WebIntegrationTest; | ||
|
||
import org.springframework.test.context.ActiveProfiles; | ||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; | ||
|
||
import org.zalando.stups.tokens.AccessToken; | ||
import org.zalando.stups.tokens.AccessTokens; | ||
import org.zalando.stups.tokens.AccessTokensBean; | ||
import org.zalando.stups.tokens.ClientCredentialsProvider; | ||
import org.zalando.stups.tokens.config.AccessTokensBeanProperties; | ||
import org.zalando.stups.tokens.config.TokenConfiguration; | ||
|
||
import com.google.common.base.Predicate; | ||
import com.google.common.collect.Iterables; | ||
|
||
/** | ||
* @author jbellmann | ||
*/ | ||
@RunWith(SpringJUnit4ClassRunner.class) | ||
@SpringApplicationConfiguration(classes = {TokenTestApplication.class}) | ||
@WebIntegrationTest(randomPort = false) | ||
@ActiveProfiles("notExposeClient") | ||
public class DoNotClientCredentialsProviderIT { | ||
|
||
static final String OAUTH2_ACCESS_TOKENS = "OAUTH2_ACCESS_TOKENS"; | ||
|
||
@Autowired(required=false) | ||
private ClientCredentialsProvider clientCredentialsProvider; | ||
|
||
@BeforeClass | ||
public static void setUp() { | ||
System.getProperties().remove(OAUTH2_ACCESS_TOKENS); | ||
} | ||
|
||
@Test | ||
public void testClientCredentialProviderIsPresent() throws InterruptedException { | ||
Assertions.assertThat(clientCredentialsProvider).isNull(); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
spring-boot-zalando-stups-tokens/src/test/resources/config/application-exposeClient.yml
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,20 @@ | ||
server: | ||
port: 9192 | ||
# | ||
# | ||
tokens: | ||
accessTokenUri: http://localhost:9191/access_token?realm=whatever | ||
credentialsDirectory: ${user.dir}/somepath/credentials | ||
refreshPercentLeft: 30 | ||
warnPercentLeft: 10 | ||
autoStartup: true | ||
exposeClientCredentialProvider: true | ||
|
||
token-configuration-list: | ||
- tokenId: firstService | ||
scopes: | ||
- refole:read | ||
- refole:write | ||
- refole:all | ||
- tokenId: secondService | ||
scopes: singleScope:all |
19 changes: 19 additions & 0 deletions
19
spring-boot-zalando-stups-tokens/src/test/resources/config/application-notExposeClient.yml
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,19 @@ | ||
server: | ||
port: 9193 | ||
# | ||
# | ||
tokens: | ||
accessTokenUri: http://localhost:9191/access_token?realm=whatever | ||
credentialsDirectory: ${user.dir}/somepath/credentials | ||
refreshPercentLeft: 30 | ||
warnPercentLeft: 10 | ||
autoStartup: true | ||
|
||
token-configuration-list: | ||
- tokenId: firstService | ||
scopes: | ||
- refole:read | ||
- refole:write | ||
- refole:all | ||
- tokenId: secondService | ||
scopes: singleScope:all |