mirror of
https://github.com/cmz0228/hysteria-dev.git
synced 2025-08-25 18:51:45 +00:00
feat: userpass auth
This commit is contained in:
65
extras/auth/password_test.go
Normal file
65
extras/auth/password_test.go
Normal file
@@ -0,0 +1,65 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"net"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestPasswordAuthenticator(t *testing.T) {
|
||||
type fields struct {
|
||||
Password string
|
||||
}
|
||||
type args struct {
|
||||
addr net.Addr
|
||||
auth string
|
||||
tx uint64
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
args args
|
||||
wantOk bool
|
||||
wantId string
|
||||
}{
|
||||
{
|
||||
name: "correct",
|
||||
fields: fields{
|
||||
Password: "yes,yes",
|
||||
},
|
||||
args: args{
|
||||
addr: nil,
|
||||
auth: "yes,yes",
|
||||
tx: 0,
|
||||
},
|
||||
wantOk: true,
|
||||
wantId: "user",
|
||||
},
|
||||
{
|
||||
name: "incorrect",
|
||||
fields: fields{
|
||||
Password: "something_somehow",
|
||||
},
|
||||
args: args{
|
||||
addr: nil,
|
||||
auth: "random",
|
||||
tx: 0,
|
||||
},
|
||||
wantOk: false,
|
||||
wantId: "",
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
a := &PasswordAuthenticator{
|
||||
Password: tt.fields.Password,
|
||||
}
|
||||
gotOk, gotId := a.Authenticate(tt.args.addr, tt.args.auth, tt.args.tx)
|
||||
if gotOk != tt.wantOk {
|
||||
t.Errorf("Authenticate() gotOk = %v, want %v", gotOk, tt.wantOk)
|
||||
}
|
||||
if gotId != tt.wantId {
|
||||
t.Errorf("Authenticate() gotId = %v, want %v", gotId, tt.wantId)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user