Skip to content

Commit

Permalink
Expect username and password in conf string
Browse files Browse the repository at this point in the history
  • Loading branch information
puzpuzpuz committed Mar 19, 2024
1 parent dc95225 commit 40f560a
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 35 deletions.
4 changes: 2 additions & 2 deletions conf_parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func confFromStr(conf string) (*lineSenderConfig, error) {
switch strings.ToLower(k) {
case "addr":
senderConf.address = v
case "user":
case "username":
switch senderConf.senderType {
case httpSenderType:
senderConf.httpUser = v
Expand All @@ -72,7 +72,7 @@ func confFromStr(conf string) (*lineSenderConfig, error) {
default:
panic("add a case for " + k)
}
case "pass":
case "password":
if senderConf.senderType != httpSenderType {
return nil, NewInvalidConfigStrError("%s is only supported for HTTP sender", k)
}
Expand Down
58 changes: 29 additions & 29 deletions conf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ func TestParserHappyCases(t *testing.T) {
},
{
name: "http and username/password",
config: fmt.Sprintf("http::addr=%s;user=%s;pass=%s", addr, user, pass),
config: fmt.Sprintf("http::addr=%s;username=%s;password=%s", addr, user, pass),
expected: qdb.ConfigData{
Schema: "http",
KeyValuePairs: map[string]string{
"addr": addr,
"user": user,
"pass": pass,
"addr": addr,
"username": user,
"password": pass,
},
},
},
Expand All @@ -107,13 +107,13 @@ func TestParserHappyCases(t *testing.T) {
},
{
name: "tcp with key and user",
config: fmt.Sprintf("tcp::addr=%s;token=%s;user=%s", addr, token, user),
config: fmt.Sprintf("tcp::addr=%s;token=%s;username=%s", addr, token, user),
expected: qdb.ConfigData{
Schema: "tcp",
KeyValuePairs: map[string]string{
"addr": addr,
"user": user,
"token": token,
"addr": addr,
"username": user,
"token": token,
},
},
},
Expand Down Expand Up @@ -179,49 +179,49 @@ func TestParserHappyCases(t *testing.T) {
},
{
name: "password with an escaped semicolon",
config: fmt.Sprintf("http::addr=%s;user=%s;pass=pass;;word", addr, user),
config: fmt.Sprintf("http::addr=%s;username=%s;password=pass;;word", addr, user),
expected: qdb.ConfigData{
Schema: "http",
KeyValuePairs: map[string]string{
"addr": addr,
"user": user,
"pass": "pass;word",
"addr": addr,
"username": user,
"password": "pass;word",
},
},
},
{
name: "password with an escaped semicolon (ending with a ';')",
config: fmt.Sprintf("http::addr=%s;user=%s;pass=pass;;word;", addr, user),
config: fmt.Sprintf("http::addr=%s;username=%s;password=pass;;word;", addr, user),
expected: qdb.ConfigData{
Schema: "http",
KeyValuePairs: map[string]string{
"addr": addr,
"user": user,
"pass": "pass;word",
"addr": addr,
"username": user,
"password": "pass;word",
},
},
},
{
name: "password with a trailing semicolon",
config: fmt.Sprintf("http::addr=%s;user=%s;pass=password;;;", addr, user),
config: fmt.Sprintf("http::addr=%s;username=%s;password=password;;;", addr, user),
expected: qdb.ConfigData{
Schema: "http",
KeyValuePairs: map[string]string{
"addr": addr,
"user": user,
"pass": "password;",
"addr": addr,
"username": user,
"password": "password;",
},
},
},
{
name: "equal sign in password",
config: fmt.Sprintf("http::addr=%s;user=%s;pass=pass=word", addr, user),
config: fmt.Sprintf("http::addr=%s;username=%s;password=pass=word", addr, user),
expected: qdb.ConfigData{
Schema: "http",
KeyValuePairs: map[string]string{
"addr": addr,
"user": user,
"pass": "pass=word",
"addr": addr,
"username": user,
"password": "pass=word",
},
},
},
Expand Down Expand Up @@ -255,12 +255,12 @@ func TestParserPathologicalCases(t *testing.T) {
},
{
name: "unescaped semicolon in password leads to unexpected end of string",
config: "http::addr=localhost:9000;user=test;pass=pass;word",
config: "http::addr=localhost:9000;username=test;password=pass;word",
expectedErrMsgContains: "unexpected end of string",
},
{
name: "unescaped semicolon in password leads to invalid key character",
config: "http::addr=localhost:9000;user=test;pass=pass;word;",
config: "http::addr=localhost:9000;username=test;password=pass;word;",
expectedErrMsgContains: "invalid key character ';'",
},
}
Expand Down Expand Up @@ -299,7 +299,7 @@ func TestHappyCasesFromConf(t *testing.T) {
testCases := []configTestCase{
{
name: "user and token",
config: fmt.Sprintf("tcp::addr=%s;user=%s;token=%s",
config: fmt.Sprintf("tcp::addr=%s;username=%s;token=%s",
addr, user, token),
expectedOpts: []qdb.LineSenderOption{
qdb.WithTcp(),
Expand Down Expand Up @@ -350,8 +350,8 @@ func TestHappyCasesFromConf(t *testing.T) {
},
},
{
name: "pass before user",
config: fmt.Sprintf("http::addr=%s;pass=%s;user=%s",
name: "password before username",
config: fmt.Sprintf("http::addr=%s;password=%s;username=%s",
addr, pass, user),
expectedOpts: []qdb.LineSenderOption{
qdb.WithHttp(),
Expand Down
4 changes: 2 additions & 2 deletions http_sender_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func TestHttpHappyCasesFromConf(t *testing.T) {
},
{
name: "pass before user",
config: fmt.Sprintf("http::addr=%s;pass=%s;user=%s",
config: fmt.Sprintf("http::addr=%s;password=%s;username=%s",
addr, pass, user),
},
{
Expand Down Expand Up @@ -95,7 +95,7 @@ func TestHttpPathologicalCasesFromConf(t *testing.T) {
testCases := []httpConfigTestCase{
{
name: "basic_and_token_auth",
config: "http::user=test_user;token=test_token",
config: "http::username=test_user;token=test_token",
expectedErr: "both basic and token",
},
{
Expand Down
4 changes: 2 additions & 2 deletions tcp_sender_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,12 @@ func TestTcpPathologicalCasesFromConf(t *testing.T) {
},
{
name: "tcp key id but no key",
config: "tcp::user=test_key_id",
config: "tcp::username=test_key_id",
expectedErr: "tcpKey is empty",
},
{
name: "invalid private key size",
config: "tcp::user=test_key_id;token=1234567890",
config: "tcp::username=test_key_id;token=1234567890",
expectedErr: "invalid auth key",
},
{
Expand Down

0 comments on commit 40f560a

Please sign in to comment.