-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[exporter/cassandra] Added authorization by username and password (#2…
…7841) Added authorization by username and password for the Casandra exporter Fixes open-telemetry/opentelemetry-collector-contrib#27827 --------- Co-authored-by: Curtis Robert <92119472+crobert-1@users.noreply.github.com>
- Loading branch information
Showing
7 changed files
with
122 additions
and
7 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package cassandraexporter | ||
|
||
import ( | ||
"errors" | ||
"testing" | ||
|
||
"github.com/gocql/gocql" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestNewCluster(t *testing.T) { | ||
testCases := map[string]struct { | ||
cfg *Config | ||
expectedAuthenticator gocql.Authenticator | ||
expectedErr error | ||
}{ | ||
"empty_auth": { | ||
cfg: withDefaultConfig(), | ||
expectedAuthenticator: nil, | ||
}, | ||
"empty_username": { | ||
cfg: withDefaultConfig(func(config *Config) { | ||
config.Auth.Password = "pass" | ||
}), | ||
expectedAuthenticator: nil, | ||
expectedErr: errors.New("empty auth.username"), | ||
}, | ||
"empty_password": { | ||
cfg: withDefaultConfig(func(config *Config) { | ||
config.Auth.UserName = "user" | ||
}), | ||
expectedAuthenticator: nil, | ||
expectedErr: errors.New("empty auth.password"), | ||
}, | ||
"success_auth": { | ||
cfg: withDefaultConfig(func(config *Config) { | ||
config.Auth.UserName = "user" | ||
config.Auth.Password = "pass" | ||
}), | ||
expectedAuthenticator: gocql.PasswordAuthenticator{ | ||
Username: "user", | ||
Password: "pass", | ||
}, | ||
}, | ||
} | ||
for name, test := range testCases { | ||
t.Run(name, func(t *testing.T) { | ||
c, err := newCluster(test.cfg) | ||
if err == nil { | ||
require.Equal(t, test.expectedAuthenticator, c.Authenticator) | ||
} | ||
require.Equal(t, test.expectedErr, err) | ||
}) | ||
} | ||
} | ||
|
||
func withDefaultConfig(fns ...func(*Config)) *Config { | ||
cfg := createDefaultConfig().(*Config) | ||
for _, fn := range fns { | ||
fn(cfg) | ||
} | ||
return cfg | ||
} |
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
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