Rename platform->cloud
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
package org.springframework.platform.config.server;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.test.IntegrationTest;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.boot.test.TestRestTemplate;
|
||||
import org.springframework.platform.config.Environment;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.web.WebAppConfiguration;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringApplicationConfiguration(classes = Application.class)
|
||||
@IntegrationTest("server.port:0")
|
||||
@WebAppConfiguration
|
||||
public class ApplicationTests {
|
||||
|
||||
@Value("${local.server.port}")
|
||||
private int port;
|
||||
|
||||
@Test
|
||||
public void contextLoads() {
|
||||
Environment environment = new TestRestTemplate().getForObject("http://localhost:" + port + "/foo/development/", Environment.class);
|
||||
assertFalse(environment.getPropertySources().isEmpty());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* Copyright 2013-2014 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
|
||||
*
|
||||
* 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 org.springframework.platform.config.server;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.platform.config.Environment;
|
||||
import org.springframework.platform.config.PropertySource;
|
||||
import org.springframework.security.rsa.crypto.RsaSecretEncryptor;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public class EncryptionControllerTests {
|
||||
|
||||
private EncryptionController controller = new EncryptionController();
|
||||
|
||||
@Test(expected = KeyNotInstalledException.class)
|
||||
public void cannotDecryptWithoutKey() {
|
||||
controller.decrypt("foo");
|
||||
}
|
||||
|
||||
@Test(expected = KeyFormatException.class)
|
||||
public void cannotUploadPublicKey() {
|
||||
controller.uploadKey("ssh-rsa ...");
|
||||
}
|
||||
|
||||
@Test(expected = KeyFormatException.class)
|
||||
public void cannotUploadPublicKeyPemFormat() {
|
||||
controller.uploadKey("---- BEGIN RSA PUBLIC KEY ...");
|
||||
}
|
||||
|
||||
@Test(expected = InvalidCipherException.class)
|
||||
public void invalidCipher() {
|
||||
controller.uploadKey("foo");
|
||||
controller.decrypt("foo");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sunnyDaySymmetricKey() {
|
||||
controller.uploadKey("foo");
|
||||
String cipher = controller.encrypt("foo");
|
||||
assertEquals("foo", controller.decrypt(cipher));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sunnyDayRsaKey() {
|
||||
controller.setEncryptor(new RsaSecretEncryptor());
|
||||
String cipher = controller.encrypt("foo");
|
||||
assertEquals("foo", controller.decrypt(cipher));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void publicKey() {
|
||||
controller.setEncryptor(new RsaSecretEncryptor());
|
||||
String key = controller.getPublicKey();
|
||||
assertTrue("Wrong key format: " + key, key.startsWith("ssh-rsa"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void decryptEnvironment() {
|
||||
controller.uploadKey("foo");
|
||||
String cipher = controller.encrypt("foo");
|
||||
Environment environment = new Environment("foo", "bar");
|
||||
environment.add(new PropertySource("spam", Collections
|
||||
.<Object, Object> singletonMap("my", "{cipher}" + cipher)));
|
||||
Environment result = controller.decrypt(environment);
|
||||
assertEquals("foo", result.getPropertySources().get(0).getSource().get("my"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void randomizedCipher() {
|
||||
controller.uploadKey("foo");
|
||||
String cipher = controller.encrypt("foo");
|
||||
assertNotEquals(cipher, controller.encrypt("foo"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
/*
|
||||
* Copyright 2013-2014 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
|
||||
*
|
||||
* 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 org.springframework.platform.config.server;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.eclipse.jgit.transport.JschConfigSessionFactory;
|
||||
import org.eclipse.jgit.transport.OpenSshConfig.Host;
|
||||
import org.eclipse.jgit.transport.SshSessionFactory;
|
||||
import org.eclipse.jgit.util.FileUtils;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.core.env.StandardEnvironment;
|
||||
import org.springframework.platform.config.Environment;
|
||||
|
||||
import com.jcraft.jsch.Session;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public class JGitEnvironmentRepositoryTests {
|
||||
|
||||
private StandardEnvironment environment = new StandardEnvironment();
|
||||
private JGitEnvironmentRepository repository = new JGitEnvironmentRepository(
|
||||
environment);
|
||||
|
||||
private File basedir = new File("target/config-repo");
|
||||
|
||||
@Before
|
||||
public void init() throws Exception {
|
||||
SshSessionFactory.setInstance(new JschConfigSessionFactory() {
|
||||
@Override
|
||||
protected void configure(Host hc, Session session) {
|
||||
session.setConfig("StrictHostKeyChecking", "no");
|
||||
}
|
||||
});
|
||||
File dotGit = new File("target/test-classes/config-repo/.git");
|
||||
File git = new File("target/test-classes/config-repo/git");
|
||||
if (git.exists()) {
|
||||
if (dotGit.exists()) {
|
||||
FileUtils.delete(dotGit, FileUtils.RECURSIVE);
|
||||
}
|
||||
}
|
||||
git.renameTo(dotGit);
|
||||
repository
|
||||
.setUri(environment
|
||||
.resolvePlaceholders("${user.name}@localhost:${user.dir}/target/test-classes/config-repo"));
|
||||
if (basedir.exists()) {
|
||||
FileUtils.delete(basedir, FileUtils.RECURSIVE);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void vanilla() {
|
||||
repository.findOne("bar", "staging", "master");
|
||||
Environment environment = repository.findOne("bar", "staging", "master");
|
||||
assertEquals(2, environment.getPropertySources().size());
|
||||
assertEquals(repository.getUri() + "/bar.properties", environment
|
||||
.getPropertySources().get(0).getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void branch() {
|
||||
repository.setBasedir(basedir);
|
||||
Environment environment = repository.findOne("bar", "staging", "raw");
|
||||
assertEquals(2, environment.getPropertySources().size());
|
||||
assertEquals(repository.getUri() + "/bar.properties", environment
|
||||
.getPropertySources().get(0).getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tag() {
|
||||
repository.setBasedir(basedir);
|
||||
Environment environment = repository.findOne("bar", "staging", "foo");
|
||||
assertEquals(2, environment.getPropertySources().size());
|
||||
assertEquals(repository.getUri() + "/bar.properties", environment
|
||||
.getPropertySources().get(0).getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void basedir() {
|
||||
repository.setBasedir(basedir);
|
||||
repository.findOne("bar", "staging", "master");
|
||||
Environment environment = repository.findOne("bar", "staging", "master");
|
||||
assertEquals(2, environment.getPropertySources().size());
|
||||
assertEquals(repository.getUri() + "/bar.properties", environment
|
||||
.getPropertySources().get(0).getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void basedirExists() throws Exception {
|
||||
assertTrue(basedir.mkdirs());
|
||||
assertTrue(new File(basedir, ".nothing").createNewFile());
|
||||
repository.setBasedir(basedir);
|
||||
repository.findOne("bar", "staging", "master");
|
||||
Environment environment = repository.findOne("bar", "staging", "master");
|
||||
assertEquals(2, environment.getPropertySources().size());
|
||||
assertEquals(repository.getUri() + "/bar.properties", environment
|
||||
.getPropertySources().get(0).getName());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright 2013-2014 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
|
||||
*
|
||||
* 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 org.springframework.platform.config.server;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.platform.config.Environment;
|
||||
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public class SpringApplicationEnvironmentRepositoryTests {
|
||||
|
||||
private SpringApplicationEnvironmentRepository repository = new SpringApplicationEnvironmentRepository();
|
||||
|
||||
@Test
|
||||
public void vanilla() {
|
||||
Environment environment = repository.findOne("foo", "development", "master");
|
||||
assertEquals(3, environment.getPropertySources().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ignoresExistingProfile() {
|
||||
System.setProperty("spring.profiles.active", "cloud");
|
||||
Environment environment = repository.findOne("foo", "main", "master");
|
||||
assertEquals(2, environment.getPropertySources().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void prefixed() {
|
||||
repository.setSearchLocations("classpath:/test");
|
||||
Environment environment = repository.findOne("foo", "development", "master");
|
||||
assertEquals(4, environment.getPropertySources().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void prefixedWithFile() {
|
||||
repository.setSearchLocations("file:./src/test/resources/test");
|
||||
Environment environment = repository.findOne("foo", "development", "master");
|
||||
assertEquals(4, environment.getPropertySources().size());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
info:
|
||||
foo: bar
|
||||
raw: true
|
||||
@@ -0,0 +1 @@
|
||||
foo: bar
|
||||
@@ -0,0 +1,2 @@
|
||||
7df4a26d5437d9d4090cd5809967f870444cde8f not-for-merge branch 'raw' of dsyer@localhost:/home/dsyer/dev/platform/config/spring-platform-config-server/target/test-classes/config-repo
|
||||
7df4a26d5437d9d4090cd5809967f870444cde8f not-for-merge tag 'foo' of dsyer@localhost:/home/dsyer/dev/platform/config/spring-platform-config-server/target/test-classes/config-repo
|
||||
@@ -0,0 +1 @@
|
||||
ref: refs/heads/raw
|
||||
@@ -0,0 +1,5 @@
|
||||
[core]
|
||||
repositoryformatversion = 0
|
||||
filemode = true
|
||||
logallrefupdates = true
|
||||
[branch "raw"]
|
||||
@@ -0,0 +1,3 @@
|
||||
1 1
|
||||
7df4a26d5437d9d4090cd5809967f870444cde8f 9f01fb972bc9617e4ea59f5c8ee3ceb5ff515cd0 9f01fb972bc9617e4ea59f5c8ee3ceb5ff515cd0
|
||||
1
|
||||
Binary file not shown.
@@ -0,0 +1 @@
|
||||
0000000000000000000000000000000000000000 7df4a26d5437d9d4090cd5809967f870444cde8f Dave Syer <dsyer@gopivotal.com> 1406860717 -0700
|
||||
@@ -0,0 +1 @@
|
||||
0000000000000000000000000000000000000000 9f01fb972bc9617e4ea59f5c8ee3ceb5ff515cd0 Dave Syer <dsyer@gopivotal.com> 1406860776 -0700 branch: Created from 9f01fb972bc9617e4ea59f5c8ee3ceb5ff515cd0
|
||||
@@ -0,0 +1 @@
|
||||
0000000000000000000000000000000000000000 7df4a26d5437d9d4090cd5809967f870444cde8f Dave Syer <dsyer@gopivotal.com> 1406860717 -0700
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1 @@
|
||||
9f01fb972bc9617e4ea59f5c8ee3ceb5ff515cd0
|
||||
@@ -0,0 +1 @@
|
||||
7df4a26d5437d9d4090cd5809967f870444cde8f
|
||||
@@ -0,0 +1 @@
|
||||
7df4a26d5437d9d4090cd5809967f870444cde8f
|
||||
@@ -0,0 +1 @@
|
||||
bar: cloud
|
||||
@@ -0,0 +1 @@
|
||||
bar: spam
|
||||
@@ -0,0 +1 @@
|
||||
foo: bar
|
||||
@@ -0,0 +1 @@
|
||||
foo: test_bar
|
||||
Reference in New Issue
Block a user