Skip to content

Commit

Permalink
added NewBasicTokenFactoryFromMap
Browse files Browse the repository at this point in the history
  • Loading branch information
kristinapathak committed May 22, 2020
1 parent f41fea3 commit 23622fa
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
8 changes: 8 additions & 0 deletions basculehttp/tokenFactory.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ func (btf BasicTokenFactory) ParseAndValidate(ctx context.Context, _ *http.Reque
return bascule.NewToken("basic", principal, bascule.NewAttributes()), nil
}

// NewBasicTokenFactoryFromMap takes a map of usernames to passwords and returns
// the BasicTokenFactory with those values.
func NewBasicTokenFactoryFromMap(m map[string]string) (BasicTokenFactory, error) {
var btf BasicTokenFactory
btf = m
return btf, nil
}

// NewBasicTokenFactoryFromList takes a list of base64 encoded basic auth keys,
// decodes them, and supplies that list in map form of username to password.
// If a username is encoded in two different auth keys, it will be overwritten
Expand Down
15 changes: 15 additions & 0 deletions basculehttp/tokenFactory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,21 @@ func TestBasicTokenFactory(t *testing.T) {
}
}

func TestNewBasicTokenFactoryFromMap(t *testing.T) {
m := map[string]string{
"user": "pass",
"a few": "thingss",
}
var expectedBtf BasicTokenFactory
expectedBtf = m

btf, err := NewBasicTokenFactoryFromMap(m)

assert := assert.New(t)
assert.Equal(expectedBtf, btf)
assert.Equal(nil, err)
}

func TestNewBasicTokenFactoryFromList(t *testing.T) {
goodKey := `dXNlcjpwYXNz`
badKeyDecode := `dXNlcjpwYXN\\\`
Expand Down

0 comments on commit 23622fa

Please sign in to comment.