mirror of
https://github.com/1f349/mjwt.git
synced 2024-12-22 07:24:05 +00:00
ParsePermStorage from string
This commit is contained in:
parent
2ecf871565
commit
82d4a4a414
@ -1,10 +1,12 @@
|
|||||||
package claims
|
package claims
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"github.com/becheran/wildmatch-go"
|
"github.com/becheran/wildmatch-go"
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
"sort"
|
"sort"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
type PermStorage struct {
|
type PermStorage struct {
|
||||||
@ -15,6 +17,16 @@ func NewPermStorage() *PermStorage {
|
|||||||
return new(PermStorage).setup()
|
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 {
|
func (p *PermStorage) setup() *PermStorage {
|
||||||
if p.values == nil {
|
if p.values == nil {
|
||||||
p.values = make(map[string]struct{})
|
p.values = make(map[string]struct{})
|
||||||
|
@ -6,6 +6,14 @@ import (
|
|||||||
"testing"
|
"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) {
|
func TestPermStorage_Set(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
ps := NewPermStorage()
|
ps := NewPermStorage()
|
||||||
|
Loading…
Reference in New Issue
Block a user