Skip to content

Commit d6f7ca9

Browse files
committed
Merge branch '4.0.x'
2 parents 0920dcc + 0dd9985 commit d6f7ca9

File tree

2 files changed

+129
-2
lines changed

2 files changed

+129
-2
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# Bootstrap components
22
org.springframework.cloud.bootstrap.BootstrapConfiguration=\
33
org.springframework.cloud.config.server.bootstrap.ConfigServerBootstrapConfiguration,\
4-
org.springframework.cloud.config.server.config.DefaultTextEncryptionAutoConfiguration,\
54
org.springframework.cloud.config.server.config.RsaEncryptionAutoConfiguration,\
5+
org.springframework.cloud.config.server.config.DefaultTextEncryptionAutoConfiguration,\
66
org.springframework.cloud.config.server.config.EncryptionAutoConfiguration
77

88
# Environment PostProcessor
99
org.springframework.boot.env.EnvironmentPostProcessor=\
1010
org.springframework.cloud.config.server.bootstrap.ConfigServerBootstrapApplicationListener
1111

1212
org.springframework.boot.diagnostics.FailureAnalyzer=\
13-
org.springframework.cloud.config.server.diagnostics.GitUriFailureAnalyzer
13+
org.springframework.cloud.config.server.diagnostics.GitUriFailureAnalyzer
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
/*
2+
* Copyright 2002-2023 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.cloud.config.server.encryption;
18+
19+
import org.junit.jupiter.api.Test;
20+
21+
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
22+
import org.springframework.boot.autoconfigure.web.ServerProperties;
23+
import org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryAutoConfiguration;
24+
import org.springframework.boot.builder.SpringApplicationBuilder;
25+
import org.springframework.cloud.bootstrap.encrypt.TextEncryptorUtils;
26+
import org.springframework.cloud.config.server.config.DefaultTextEncryptionAutoConfiguration;
27+
import org.springframework.cloud.config.server.config.RsaEncryptionAutoConfiguration;
28+
import org.springframework.context.ConfigurableApplicationContext;
29+
import org.springframework.security.crypto.encrypt.Encryptors;
30+
import org.springframework.security.crypto.encrypt.TextEncryptor;
31+
import org.springframework.security.rsa.crypto.RsaSecretEncryptor;
32+
33+
import static org.assertj.core.api.Assertions.assertThat;
34+
35+
/**
36+
* @author Ryan Baxter
37+
*/
38+
public class EncryptionAutoConfigurationTests {
39+
40+
@Test
41+
public void defaultNoKeyAutoConfigurationTest() {
42+
ConfigurableApplicationContext context = new SpringApplicationBuilder(
43+
DefaultTextEncryptionAutoConfiguration.class, RsaEncryptionAutoConfiguration.class,
44+
ServletWebServerFactoryAutoConfiguration.class, ServerProperties.class,
45+
PropertyPlaceholderAutoConfiguration.class).properties("server.port=0").run();
46+
TextEncryptor textEncryptor = context.getBean(TextEncryptor.class);
47+
String[] textEncryptorLocatorNames = context.getBeanNamesForType(TextEncryptorLocator.class);
48+
assertThat(textEncryptor).isInstanceOf(TextEncryptorUtils.FailsafeTextEncryptor.class);
49+
assertThat(textEncryptorLocatorNames).isEmpty();
50+
context.close();
51+
}
52+
53+
@Test
54+
public void defaultKeyStoreAutoConfigurationTest() {
55+
ConfigurableApplicationContext context = new SpringApplicationBuilder(
56+
DefaultTextEncryptionAutoConfiguration.class, RsaEncryptionAutoConfiguration.class,
57+
ServletWebServerFactoryAutoConfiguration.class, ServerProperties.class,
58+
PropertyPlaceholderAutoConfiguration.class)
59+
.properties("server.port=0", "encrypt.key-store.location=classpath:server.jks",
60+
"encrypt.key-store.password=letmein", "encrypt.key-store.alias=myKey")
61+
.run();
62+
TextEncryptor textEncryptor = context.getBean(TextEncryptor.class);
63+
TextEncryptorLocator textEncryptorLocator = context.getBean(TextEncryptorLocator.class);
64+
assertThat(textEncryptor).isInstanceOf(RsaSecretEncryptor.class);
65+
assertThat(textEncryptorLocator).isInstanceOf(KeyStoreTextEncryptorLocator.class);
66+
context.close();
67+
}
68+
69+
@Test
70+
public void defaultKeyAutoConfigurationTest() {
71+
ConfigurableApplicationContext context = new SpringApplicationBuilder(
72+
DefaultTextEncryptionAutoConfiguration.class, RsaEncryptionAutoConfiguration.class,
73+
ServletWebServerFactoryAutoConfiguration.class, ServerProperties.class,
74+
PropertyPlaceholderAutoConfiguration.class).properties("server.port=0", "encrypt.key=mykey").run();
75+
TextEncryptor textEncryptor = context.getBean(TextEncryptor.class);
76+
String[] textEncryptorLocatorNames = context.getBeanNamesForType(TextEncryptorLocator.class);
77+
assertThat(textEncryptor.getClass().getName())
78+
.isEqualTo("org.springframework.security.crypto.encrypt.HexEncodingTextEncryptor");
79+
assertThat(textEncryptorLocatorNames).isEmpty();
80+
context.close();
81+
}
82+
83+
@Test
84+
public void bootstrapNoKeyAutoConfigurationTest() {
85+
ConfigurableApplicationContext context = new SpringApplicationBuilder(
86+
DefaultTextEncryptionAutoConfiguration.class, RsaEncryptionAutoConfiguration.class,
87+
ServletWebServerFactoryAutoConfiguration.class, ServerProperties.class,
88+
PropertyPlaceholderAutoConfiguration.class)
89+
.properties("server.port=0", "spring.cloud.bootstrap.enabled=true").run();
90+
TextEncryptor textEncryptor = context.getBean(TextEncryptor.class);
91+
String[] textEncryptorLocatorNames = context.getBeanNamesForType(TextEncryptorLocator.class);
92+
assertThat(textEncryptor.getClass().isInstance(Encryptors.noOpText().getClass()));
93+
assertThat(textEncryptorLocatorNames).isEmpty();
94+
context.close();
95+
}
96+
97+
@Test
98+
public void bootstrapKeyAutoConfigurationTests() {
99+
ConfigurableApplicationContext context = new SpringApplicationBuilder(
100+
DefaultTextEncryptionAutoConfiguration.class, RsaEncryptionAutoConfiguration.class,
101+
ServletWebServerFactoryAutoConfiguration.class, ServerProperties.class,
102+
PropertyPlaceholderAutoConfiguration.class)
103+
.properties("server.port=0", "spring.cloud.bootstrap.enabled=true", "encrypt.key=mykey").run();
104+
TextEncryptor textEncryptor = context.getBean(TextEncryptor.class);
105+
assertThat(textEncryptor.getClass().getName())
106+
.isEqualTo("org.springframework.security.crypto.encrypt.HexEncodingTextEncryptor");
107+
context.close();
108+
}
109+
110+
@Test
111+
public void bootstrapKeyStoreAutoConfigurationTest() {
112+
ConfigurableApplicationContext context = new SpringApplicationBuilder(
113+
DefaultTextEncryptionAutoConfiguration.class, RsaEncryptionAutoConfiguration.class,
114+
ServletWebServerFactoryAutoConfiguration.class, ServerProperties.class,
115+
PropertyPlaceholderAutoConfiguration.class)
116+
.properties("server.port=0", "spring.cloud.bootstrap.enabled=true",
117+
"encrypt.key-store.location=classpath:server.jks", "encrypt.key-store.password=letmein",
118+
"encrypt.key-store.alias=myKey")
119+
.run();
120+
TextEncryptor textEncryptor = context.getBean(TextEncryptor.class);
121+
TextEncryptorLocator textEncryptorLocator = context.getBean(TextEncryptorLocator.class);
122+
assertThat(textEncryptor).isInstanceOf(LocatorTextEncryptor.class);
123+
assertThat(textEncryptorLocator).isInstanceOf(KeyStoreTextEncryptorLocator.class);
124+
context.close();
125+
}
126+
127+
}

0 commit comments

Comments
 (0)