Skip to content

Commit 12abd5e

Browse files
authored
Add back secure bundle based authentication to cloud (#283)
1 parent 644d017 commit 12abd5e

3 files changed

Lines changed: 40 additions & 0 deletions

File tree

cpp-driver/gtests/src/unit/tests/test_cloud_secure_connect_config.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ using datastax::internal::core::ClusterMetadataResolver;
6161
using datastax::internal::core::ClusterSettings;
6262
using datastax::internal::core::Config;
6363
using datastax::internal::core::HttpClient;
64+
using datastax::internal::enterprise::DsePlainTextAuthProvider;
6465
using datastax::internal::json::StringBuffer;
6566
using datastax::internal::json::Writer;
6667

@@ -121,6 +122,10 @@ class CloudSecureConnectionConfigTest : public HttpTest {
121122
int port = 1443) {
122123
Writer<StringBuffer> writer(buffer);
123124
writer.StartObject();
125+
writer.Key("username");
126+
writer.String("DataStax");
127+
writer.Key("password");
128+
writer.String("Constellation");
124129
writer.Key("host");
125130
writer.String(host.c_str());
126131
writer.Key("port");
@@ -166,6 +171,8 @@ TEST_F(CloudSecureConnectionConfigTest, CredsV1) {
166171
create_zip_file(buffer.GetString());
167172

168173
EXPECT_TRUE(cloud_config.load(creds_zip_file(), &config));
174+
EXPECT_EQ("DataStax", cloud_config.username());
175+
EXPECT_EQ("Constellation", cloud_config.password());
169176
EXPECT_EQ("cloud.datastax.com", cloud_config.host());
170177
EXPECT_EQ(1443, cloud_config.port());
171178
EXPECT_EQ("database_as_a_service", cloud_config.keyspace());
@@ -174,6 +181,7 @@ TEST_F(CloudSecureConnectionConfigTest, CredsV1) {
174181
EXPECT_EQ(key(), cloud_config.key());
175182

176183
EXPECT_TRUE(config.ssl_context());
184+
EXPECT_TRUE(dynamic_cast<DsePlainTextAuthProvider*>(config.auth_provider().get()) != NULL);
177185
}
178186

179187
TEST_F(CloudSecureConnectionConfigTest, CredsV1WithoutCreds) {
@@ -193,6 +201,8 @@ TEST_F(CloudSecureConnectionConfigTest, CredsV1WithoutCreds) {
193201
create_zip_file(buffer.GetString());
194202

195203
EXPECT_TRUE(cloud_config.load(creds_zip_file(), &config));
204+
EXPECT_EQ("", cloud_config.username());
205+
EXPECT_EQ("", cloud_config.password());
196206
EXPECT_EQ("bigdata.datastax.com", cloud_config.host());
197207
EXPECT_EQ(2443, cloud_config.port());
198208
EXPECT_EQ("datastax", cloud_config.keyspace());
@@ -201,6 +211,8 @@ TEST_F(CloudSecureConnectionConfigTest, CredsV1WithoutCreds) {
201211
EXPECT_EQ(key(), cloud_config.key());
202212

203213
EXPECT_TRUE(config.ssl_context());
214+
EXPECT_TRUE(dynamic_cast<DsePlainTextAuthProvider*>(config.auth_provider().get()) ==
215+
NULL); // Not configured
204216
}
205217

206218
TEST_F(CloudSecureConnectionConfigTest, InvalidCredsV1ConfigMissingHost) {
@@ -209,6 +221,10 @@ TEST_F(CloudSecureConnectionConfigTest, InvalidCredsV1ConfigMissingHost) {
209221
StringBuffer buffer;
210222
Writer<StringBuffer> writer(buffer);
211223
writer.StartObject();
224+
writer.Key("username");
225+
writer.String("DataStax");
226+
writer.Key("password");
227+
writer.String("Constellation");
212228
writer.Key("port");
213229
writer.Int(1443);
214230
writer.Key("keyspace");
@@ -225,6 +241,10 @@ TEST_F(CloudSecureConnectionConfigTest, InvalidCredsV1ConfigMissingPort) {
225241
StringBuffer buffer;
226242
Writer<StringBuffer> writer(buffer);
227243
writer.StartObject();
244+
writer.Key("username");
245+
writer.String("DataStax");
246+
writer.Key("password");
247+
writer.String("Constellation");
228248
writer.Key("host");
229249
writer.String("cloud.datastax.com");
230250
writer.Key("keyspace");
@@ -241,6 +261,10 @@ TEST_F(CloudSecureConnectionConfigTest, InvalidCredsV1ConfigMissingKeyspace) {
241261
StringBuffer buffer;
242262
Writer<StringBuffer> writer(buffer);
243263
writer.StartObject();
264+
writer.Key("username");
265+
writer.String("DataStax");
266+
writer.Key("password");
267+
writer.String("Constellation");
244268
writer.Key("host");
245269
writer.String("cloud.datastax.com");
246270
writer.Key("port");

cpp-driver/src/cloud_secure_connection_config.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,18 @@ bool CloudSecureConnectionConfig::load(const String& filename, Config* config /*
246246
return false;
247247
}
248248

249+
if (document.HasMember("username") && document["username"].IsString()) {
250+
username_ = document["username"].GetString();
251+
}
252+
if (document.HasMember("password") && document["password"].IsString()) {
253+
password_ = document["password"].GetString();
254+
}
255+
256+
if (config && (!username_.empty() || !password_.empty())) {
257+
config->set_auth_provider(
258+
AuthProvider::Ptr(new enterprise::DsePlainTextAuthProvider(username_, password_, "")));
259+
}
260+
249261
if (!document.HasMember("host") || !document["host"].IsString()) {
250262
LOG_ERROR(CLOUD_ERROR "Missing host");
251263
return false;

cpp-driver/src/cloud_secure_connection_config.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ class CloudSecureConnectionConfig {
3030
bool load(const String& filename, Config* config = NULL);
3131
bool is_loaded() const { return is_loaded_; }
3232

33+
const String& username() const { return username_; }
34+
const String& password() const { return password_; }
3335
const String& host() const { return host_; }
3436
int port() const { return port_; }
3537
const String& keyspace() const { return keyspace_; }
@@ -40,6 +42,8 @@ class CloudSecureConnectionConfig {
4042

4143
private:
4244
bool is_loaded_;
45+
String username_;
46+
String password_;
4347
String host_;
4448
int port_;
4549
String keyspace_;

0 commit comments

Comments
 (0)