credential/github: case insensitive mappings

This commit is contained in:
Mitchell Hashimoto 2015-05-11 10:24:39 -07:00
parent 1ee7218796
commit 4e861f29bc
3 changed files with 21 additions and 11 deletions

View File

@ -16,7 +16,10 @@ func Factory(map[string]string) (logical.Backend, error) {
func Backend() *framework.Backend {
var b backend
b.Map = &framework.PolicyMap{
PathMap: framework.PathMap{Name: "teams"},
PathMap: framework.PathMap{
Name: "teams",
CaseInsensitive: true,
},
DefaultKey: "default",
}
b.Backend = &framework.Backend{

View File

@ -14,8 +14,9 @@ func TestBackend_basic(t *testing.T) {
Backend: Backend(),
Steps: []logicaltest.TestStep{
testAccStepConfig(t),
testAccMap(t),
testAccLogin(t),
testAccMap(t, "default", "foo"),
testAccMap(t, "oWnErs", "bar"),
testAccLogin(t, []string{"bar", "foo"}),
},
})
}
@ -40,17 +41,17 @@ func testAccStepConfig(t *testing.T) logicaltest.TestStep {
}
}
func testAccMap(t *testing.T) logicaltest.TestStep {
func testAccMap(t *testing.T, k string, v string) logicaltest.TestStep {
return logicaltest.TestStep{
Operation: logical.WriteOperation,
Path: "map/teams/default",
Path: "map/teams/" + k,
Data: map[string]interface{}{
"value": "foo",
"value": v,
},
}
}
func testAccLogin(t *testing.T) logicaltest.TestStep {
func testAccLogin(t *testing.T, keys []string) logicaltest.TestStep {
return logicaltest.TestStep{
Operation: logical.WriteOperation,
Path: "login",
@ -59,6 +60,6 @@ func testAccLogin(t *testing.T) logicaltest.TestStep {
},
Unauthenticated: true,
Check: logicaltest.TestCheckAuth([]string{"foo"}),
Check: logicaltest.TestCheckAuth(keys),
}
}

View File

@ -15,9 +15,10 @@ import (
// The primary use case for this is for credential providers to do their
// mapping to policies.
type PathMap struct {
Prefix string
Name string
Schema map[string]*FieldSchema
Prefix string
Name string
Schema map[string]*FieldSchema
CaseInsensitive bool
once sync.Once
}
@ -41,6 +42,11 @@ func (p *PathMap) init() {
func (p *PathMap) pathStruct(k string) *PathStruct {
p.once.Do(p.init)
// If we don't care about casing, store everything lowercase
if p.CaseInsensitive {
k = strings.ToLower(k)
}
return &PathStruct{
Name: fmt.Sprintf("map/%s/%s", p.Name, k),
Schema: p.Schema,