mediocre-blog/srv/src/http/auth_test.go

25 lines
475 B
Go
Raw Normal View History

2022-05-20 17:17:31 +00:00
package http
2022-05-20 03:35:45 +00:00
import (
2022-05-20 20:54:26 +00:00
"context"
2022-05-20 03:35:45 +00:00
"testing"
2022-05-20 20:54:26 +00:00
"time"
2022-05-20 03:35:45 +00:00
"github.com/stretchr/testify/assert"
)
func TestAuther(t *testing.T) {
2022-05-20 20:54:26 +00:00
ctx := context.Background()
2022-05-20 03:35:45 +00:00
password := "foo"
hashedPassword := NewPasswordHash(password)
auther := NewAuther(map[string]string{
"FOO": hashedPassword,
2022-05-20 20:54:26 +00:00
}, 1*time.Millisecond)
2022-05-20 03:35:45 +00:00
2022-05-20 20:54:26 +00:00
assert.False(t, auther.Allowed(ctx, "BAR", password))
assert.False(t, auther.Allowed(ctx, "FOO", "bar"))
assert.True(t, auther.Allowed(ctx, "FOO", password))
2022-05-20 03:35:45 +00:00
}