mirror of
https://github.com/jech/galene.git
synced 2024-11-22 00:25:58 +01:00
Expand high-level token test.
This commit is contained in:
parent
8a94f4a716
commit
368791648f
1 changed files with 31 additions and 6 deletions
|
@ -1,30 +1,55 @@
|
|||
package token
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"path/filepath"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestBad(t *testing.T) {
|
||||
func TestToken(t *testing.T) {
|
||||
d := t.TempDir()
|
||||
tokens = state{
|
||||
filename: filepath.Join(d, "test.jsonl"),
|
||||
}
|
||||
|
||||
f, err := os.OpenFile(tokens.filename,
|
||||
os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0600,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("Create: %v", err)
|
||||
}
|
||||
defer f.Close()
|
||||
f.Close()
|
||||
|
||||
token, err := Parse("foo", nil)
|
||||
future := time.Now().Add(time.Hour)
|
||||
user := "user"
|
||||
_, err = Add(&Stateful{
|
||||
Token: "token",
|
||||
Group: "group",
|
||||
Username: &user,
|
||||
Permissions: []string{"present"},
|
||||
Expires: &future,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("Add: %v", err)
|
||||
}
|
||||
|
||||
token, err := Parse("token", nil)
|
||||
if err != nil || token == nil {
|
||||
t.Fatalf("Parse: %v", err)
|
||||
}
|
||||
|
||||
_, _, err = token.Check("galene.org:8443", "group", &user)
|
||||
if err != nil {
|
||||
t.Errorf("Check: %v", err)
|
||||
}
|
||||
|
||||
token, err = Parse("bad", nil)
|
||||
if err == nil {
|
||||
t.Errorf("Expected error, got %v", token)
|
||||
}
|
||||
|
||||
token, err = Parse("foo", []map[string]interface{}{})
|
||||
token, err = Parse("bad", []map[string]interface{}{})
|
||||
if err == nil {
|
||||
t.Errorf("Expected error, got %v", token)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue