-
Notifications
You must be signed in to change notification settings - Fork 1k
Send using password: NO when no password is used
#1078
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
a8b8fe1
9c44be5
c20a99a
4d0921f
7093a09
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| package server | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestCheckSha2CacheCredentials_EmptyPassword(t *testing.T) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this test be put into auth_test.go, below TestCompareSha256PasswordAuthData_EmptyPassword?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do you want to move
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, your reason is to use auth_switch_response_test.go to check function in auth_switch_response.go. I think it's reasonable from this view. |
||
| tests := []struct { | ||
| name string | ||
| clientAuthData []byte | ||
| serverPassword string | ||
| wantErr error | ||
| }{ | ||
| { | ||
| name: "empty client auth, empty server password", | ||
| clientAuthData: []byte{}, | ||
| serverPassword: "", | ||
| wantErr: nil, | ||
| }, | ||
| { | ||
| name: "empty client auth, non-empty server password", | ||
| clientAuthData: []byte{}, | ||
| serverPassword: "secret", | ||
| wantErr: ErrAccessDeniedNoPassword, | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| c := &Conn{ | ||
| credential: Credential{Password: tt.serverPassword}, | ||
| } | ||
| err := c.checkSha2CacheCredentials(tt.clientAuthData, c.credential) | ||
| if tt.wantErr == nil { | ||
| require.NoError(t, err) | ||
| } else { | ||
| require.ErrorIs(t, err, tt.wantErr) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| package server | ||
|
|
||
| import ( | ||
| "errors" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestErrAccessDenied(t *testing.T) { | ||
| require.True(t, errors.Is(ErrAccessDenied, ErrAccessDenied)) | ||
| require.True(t, errors.Is(ErrAccessDeniedNoPassword, ErrAccessDenied)) | ||
| require.False(t, errors.Is(ErrAccessDenied, ErrAccessDeniedNoPassword)) | ||
| } | ||
|
|
||
| func TestCompareNativePasswordAuthData_EmptyPassword(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| clientAuthData []byte | ||
| serverPassword string | ||
| wantErr error | ||
| }{ | ||
| { | ||
| name: "empty client auth, empty server password", | ||
| clientAuthData: []byte{}, | ||
| serverPassword: "", | ||
| wantErr: nil, | ||
| }, | ||
| { | ||
| name: "empty client auth, non-empty server password", | ||
| clientAuthData: []byte{}, | ||
| serverPassword: "secret", | ||
| wantErr: ErrAccessDeniedNoPassword, | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| c := &Conn{ | ||
| credential: Credential{Password: tt.serverPassword}, | ||
| } | ||
| err := c.compareNativePasswordAuthData(tt.clientAuthData, c.credential) | ||
| if tt.wantErr == nil { | ||
| require.NoError(t, err) | ||
| } else { | ||
| require.ErrorIs(t, err, tt.wantErr) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestCompareSha256PasswordAuthData_EmptyPassword(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| clientAuthData []byte | ||
| serverPassword string | ||
| wantErr error | ||
| }{ | ||
| { | ||
| name: "empty client auth, empty server password", | ||
| clientAuthData: []byte{}, | ||
| serverPassword: "", | ||
| wantErr: nil, | ||
| }, | ||
| { | ||
| name: "empty client auth, non-empty server password", | ||
| clientAuthData: []byte{}, | ||
| serverPassword: "secret", | ||
| wantErr: ErrAccessDeniedNoPassword, | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| c := &Conn{ | ||
| credential: Credential{Password: tt.serverPassword}, | ||
| } | ||
| err := c.compareSha256PasswordAuthData(tt.clientAuthData, c.credential) | ||
| if tt.wantErr == nil { | ||
| require.NoError(t, err) | ||
| } else { | ||
| require.ErrorIs(t, err, tt.wantErr) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestCompareCacheSha2PasswordAuthData_EmptyPassword(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| clientAuthData []byte | ||
| serverPassword string | ||
| wantErr error | ||
| }{ | ||
| { | ||
| name: "empty client auth, empty server password", | ||
| clientAuthData: []byte{}, | ||
| serverPassword: "", | ||
| wantErr: nil, | ||
| }, | ||
| { | ||
| name: "empty client auth, non-empty server password", | ||
| clientAuthData: []byte{}, | ||
| serverPassword: "secret", | ||
| wantErr: ErrAccessDeniedNoPassword, | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| c := &Conn{ | ||
| credential: Credential{Password: tt.serverPassword}, | ||
| } | ||
| err := c.compareCacheSha2PasswordAuthData(tt.clientAuthData) | ||
| if tt.wantErr == nil { | ||
| require.NoError(t, err) | ||
| } else { | ||
| require.ErrorIs(t, err, tt.wantErr) | ||
| } | ||
| }) | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.