Skip to content

Commit 1143396

Browse files
Add smoke tests to verify Couchbase SSL connections
See gh-34811
1 parent d4107a8 commit 1143396

File tree

17 files changed

+591
-3
lines changed

17 files changed

+591
-3
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/couchbase/CouchbaseAutoConfiguration.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,7 @@ private ClusterEnvironment.Builder initializeEnvironmentBuilder(CouchbaseConnect
120120
builder.ioConfig((config) -> config.maxHttpConnections(io.getMaxEndpoints())
121121
.numKvConnections(io.getMinEndpoints())
122122
.idleHttpConnectionTimeout(io.getIdleHttpConnectionTimeout()));
123-
if ((connectionDetails instanceof PropertiesCouchbaseConnectionDetails)
124-
&& this.properties.getEnv().getSsl().getEnabled()) {
123+
if (this.properties.getEnv().getSsl().getEnabled()) {
125124
configureSsl(builder, sslBundles);
126125
}
127126
return builder;

spring-boot-project/spring-boot-tools/spring-boot-test-support/src/main/java/org/springframework/boot/testsupport/testcontainers/DockerImageNames.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public final class DockerImageNames {
3232

3333
private static final String CASSANDRA_VERSION = "3.11.10";
3434

35-
private static final String COUCHBASE_VERSION = "6.5.1";
35+
private static final String COUCHBASE_VERSION = "7.1.4";
3636

3737
private static final String ELASTICSEARCH_VERSION = "7.17.5";
3838

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
plugins {
2+
id "java"
3+
id "org.springframework.boot.conventions"
4+
}
5+
6+
description = "Spring Boot Data Couchbase smoke test"
7+
8+
dependencies {
9+
implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-data-couchbase"))
10+
implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-data-couchbase-reactive"))
11+
12+
testImplementation(project(":spring-boot-project:spring-boot-test"))
13+
testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test"))
14+
testImplementation(project(":spring-boot-project:spring-boot-tools:spring-boot-test-support"))
15+
testImplementation(project(":spring-boot-project:spring-boot-testcontainers"))
16+
testImplementation("com.squareup.okhttp3:okhttp")
17+
testImplementation("io.projectreactor:reactor-core")
18+
testImplementation("io.projectreactor:reactor-test")
19+
testImplementation("org.junit.jupiter:junit-jupiter")
20+
testImplementation("org.junit.platform:junit-platform-engine")
21+
testImplementation("org.junit.platform:junit-platform-launcher")
22+
testImplementation("org.testcontainers:junit-jupiter")
23+
testImplementation("org.testcontainers:testcontainers")
24+
testImplementation("org.testcontainers:couchbase")
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright 2012-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 smoketest.data.couchbase;
18+
19+
import org.springframework.boot.autoconfigure.SpringBootApplication;
20+
21+
@SpringBootApplication
22+
public class SampleCouchbaseApplication {
23+
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright 2012-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 smoketest.data.couchbase;
18+
19+
import org.springframework.data.annotation.Id;
20+
import org.springframework.data.couchbase.core.mapping.Document;
21+
import org.springframework.data.couchbase.core.mapping.id.GeneratedValue;
22+
import org.springframework.data.couchbase.core.mapping.id.GenerationStrategy;
23+
24+
@Document
25+
public class SampleDocument {
26+
27+
@Id
28+
@GeneratedValue(strategy = GenerationStrategy.UNIQUE)
29+
private String id;
30+
31+
private String text;
32+
33+
public String getId() {
34+
return this.id;
35+
}
36+
37+
public void setId(String id) {
38+
this.id = id;
39+
}
40+
41+
public String getText() {
42+
return this.text;
43+
}
44+
45+
public void setText(String text) {
46+
this.text = text;
47+
}
48+
49+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright 2012-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 smoketest.data.couchbase;
18+
19+
import org.springframework.data.couchbase.repository.ReactiveCouchbaseRepository;
20+
21+
interface SampleReactiveRepository extends ReactiveCouchbaseRepository<SampleDocument, String> {
22+
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright 2012-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 smoketest.data.couchbase;
18+
19+
import org.springframework.data.couchbase.repository.CouchbaseRepository;
20+
21+
interface SampleRepository extends CouchbaseRepository<SampleDocument, String> {
22+
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright 2012-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 smoketest.data.couchbase;
18+
19+
import org.springframework.data.couchbase.core.CouchbaseTemplate;
20+
import org.springframework.stereotype.Service;
21+
22+
@Service
23+
public class SampleService {
24+
25+
private final CouchbaseTemplate couchbaseTemplate;
26+
27+
public SampleService(CouchbaseTemplate couchbaseTemplate) {
28+
this.couchbaseTemplate = couchbaseTemplate;
29+
}
30+
31+
public SampleDocument findById(String id) {
32+
return this.couchbaseTemplate.findById(SampleDocument.class).one(id);
33+
}
34+
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* Copyright 2012-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 smoketest.data.couchbase;
18+
19+
import java.time.Duration;
20+
21+
import org.junit.jupiter.api.Test;
22+
import org.testcontainers.couchbase.BucketDefinition;
23+
import org.testcontainers.couchbase.CouchbaseContainer;
24+
import org.testcontainers.junit.jupiter.Container;
25+
import org.testcontainers.junit.jupiter.Testcontainers;
26+
27+
import org.springframework.beans.factory.annotation.Autowired;
28+
import org.springframework.boot.test.context.SpringBootTest;
29+
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
30+
import org.springframework.data.couchbase.core.ReactiveCouchbaseTemplate;
31+
32+
import static org.assertj.core.api.Assertions.assertThat;
33+
34+
/**
35+
* Smoke tests for Couchbase using reactive repositories with SSL.
36+
*
37+
* @author Scott Frederick
38+
*/
39+
@Testcontainers(disabledWithoutDocker = true)
40+
@SpringBootTest(properties = { "spring.couchbase.env.ssl.bundle=client", "spring.data.couchbase.bucket-name=cbbucket",
41+
"spring.ssl.bundle.pem.client.keystore.certificate=classpath:ssl/test-client.crt",
42+
"spring.ssl.bundle.pem.client.keystore.private-key=classpath:ssl/test-client.key",
43+
"spring.ssl.bundle.pem.client.truststore.certificate=classpath:ssl/test-ca.crt" })
44+
class SampleCouchbaseApplicationReactiveSslTests {
45+
46+
private static final String BUCKET_NAME = "cbbucket";
47+
48+
@Container
49+
@ServiceConnection
50+
static final CouchbaseContainer couchbase = new SecureCouchbaseContainer()
51+
.withBucket(new BucketDefinition(BUCKET_NAME));
52+
53+
@Autowired
54+
private ReactiveCouchbaseTemplate couchbaseTemplate;
55+
56+
@Autowired
57+
private SampleReactiveRepository repository;
58+
59+
@Test
60+
void testRepository() {
61+
SampleDocument document = new SampleDocument();
62+
document.setText("Look, new @DataCouchbaseTest!");
63+
document = this.repository.save(document).block(Duration.ofSeconds(30));
64+
assertThat(document.getId()).isNotNull();
65+
assertThat(this.couchbaseTemplate.getBucketName()).isEqualTo(BUCKET_NAME);
66+
this.repository.deleteAll();
67+
}
68+
69+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Copyright 2012-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 smoketest.data.couchbase;
18+
19+
import org.junit.jupiter.api.Test;
20+
import org.testcontainers.couchbase.BucketDefinition;
21+
import org.testcontainers.couchbase.CouchbaseContainer;
22+
import org.testcontainers.junit.jupiter.Container;
23+
import org.testcontainers.junit.jupiter.Testcontainers;
24+
25+
import org.springframework.beans.factory.annotation.Autowired;
26+
import org.springframework.boot.test.context.SpringBootTest;
27+
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
28+
import org.springframework.data.couchbase.core.CouchbaseTemplate;
29+
30+
import static org.assertj.core.api.Assertions.assertThat;
31+
32+
/**
33+
* Smoke tests for Couchbase with SSL.
34+
*
35+
* @author Scott Frederick
36+
*/
37+
@Testcontainers(disabledWithoutDocker = true)
38+
@SpringBootTest(properties = { "spring.couchbase.env.ssl.bundle=client", "spring.couchbase.env.timeouts.connect=2m",
39+
"spring.data.couchbase.bucket-name=cbbucket",
40+
"spring.ssl.bundle.pem.client.keystore.certificate=classpath:ssl/test-client.crt",
41+
"spring.ssl.bundle.pem.client.keystore.private-key=classpath:ssl/test-client.key",
42+
"spring.ssl.bundle.pem.client.truststore.certificate=classpath:ssl/test-ca.crt" })
43+
class SampleCouchbaseApplicationSslTests {
44+
45+
private static final String BUCKET_NAME = "cbbucket";
46+
47+
@Container
48+
@ServiceConnection
49+
static final CouchbaseContainer couchbase = new SecureCouchbaseContainer()
50+
.withBucket(new BucketDefinition(BUCKET_NAME));
51+
52+
@Autowired
53+
private CouchbaseTemplate couchbaseTemplate;
54+
55+
@Autowired
56+
private SampleRepository repository;
57+
58+
@Test
59+
void testRepository() {
60+
SampleDocument document = new SampleDocument();
61+
document.setText("Look, new @DataCouchbaseTest!");
62+
document = this.repository.save(document);
63+
assertThat(document.getId()).isNotNull();
64+
assertThat(this.couchbaseTemplate.getBucketName()).isEqualTo(BUCKET_NAME);
65+
this.repository.deleteAll();
66+
}
67+
68+
}

0 commit comments

Comments
 (0)