-
Notifications
You must be signed in to change notification settings - Fork 2
/
authentication.go
44 lines (37 loc) · 1.1 KB
/
authentication.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package spectest
import "fmt"
// basicAuth is represents the basic auth credentials
type basicAuth struct {
// userName is the userName for basic auth
userName string
// password is the password for basic auth
password string
}
// newBasicAuth creates a new basic auth
func newBasicAuth(userName, password string) basicAuth {
return basicAuth{
userName: userName,
password: password,
}
}
// isUserNameEmpty returns true if the userName is empty
func (b basicAuth) isUserNameEmpty() bool {
return b.userName == ""
}
// isPasswordEmpty returns true if the password is empty
func (b basicAuth) isPasswordEmpty() bool {
return b.password == ""
}
// auth will authenticate the user
// auth will return an error if the user is not authenticated
func (b basicAuth) auth(userName, password string) error {
if b.userName != userName {
return fmt.Errorf("basic auth request username '%s' did not match mock username '%s'",
userName, b.userName)
}
if b.password != password {
return fmt.Errorf("basic auth request password '%s' did not match mock password '%s'",
password, b.password)
}
return nil
}