From 23622fa8a6e1dbeb11c16e63e6f6d057baddb9be Mon Sep 17 00:00:00 2001 From: Kristina Spring Date: Fri, 22 May 2020 11:40:13 -0700 Subject: [PATCH] added NewBasicTokenFactoryFromMap --- basculehttp/tokenFactory.go | 8 ++++++++ basculehttp/tokenFactory_test.go | 15 +++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/basculehttp/tokenFactory.go b/basculehttp/tokenFactory.go index 05a29ea..b09951a 100644 --- a/basculehttp/tokenFactory.go +++ b/basculehttp/tokenFactory.go @@ -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 diff --git a/basculehttp/tokenFactory_test.go b/basculehttp/tokenFactory_test.go index 0f52f49..58a5412 100644 --- a/basculehttp/tokenFactory_test.go +++ b/basculehttp/tokenFactory_test.go @@ -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\\\`