mirror of
https://github.com/1f349/mjwt.git
synced 2024-11-09 22:22:48 +00:00
ParsePermStorage from string
This commit is contained in:
parent
2ecf871565
commit
82d4a4a414
@ -1,10 +1,12 @@
|
||||
package claims
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"encoding/json"
|
||||
"github.com/becheran/wildmatch-go"
|
||||
"gopkg.in/yaml.v3"
|
||||
"sort"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type PermStorage struct {
|
||||
@ -15,6 +17,16 @@ func NewPermStorage() *PermStorage {
|
||||
return new(PermStorage).setup()
|
||||
}
|
||||
|
||||
func ParsePermStorage(perms string) *PermStorage {
|
||||
ps := NewPermStorage()
|
||||
sc := bufio.NewScanner(strings.NewReader(perms))
|
||||
sc.Split(bufio.ScanWords)
|
||||
for sc.Scan() {
|
||||
ps.Set(sc.Text())
|
||||
}
|
||||
return ps
|
||||
}
|
||||
|
||||
func (p *PermStorage) setup() *PermStorage {
|
||||
if p.values == nil {
|
||||
p.values = make(map[string]struct{})
|
||||
|
@ -6,6 +6,14 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestParsePermStorage(t *testing.T) {
|
||||
t.Parallel()
|
||||
ps := ParsePermStorage("mjwt:test mjwt:test2")
|
||||
if _, ok := ps.values["mjwt:test"]; !ok {
|
||||
assert.Fail(t, "perm not set")
|
||||
}
|
||||
}
|
||||
|
||||
func TestPermStorage_Set(t *testing.T) {
|
||||
t.Parallel()
|
||||
ps := NewPermStorage()
|
||||
|
Loading…
Reference in New Issue
Block a user