Skip to content

Commit

Permalink
Use userInfo for Originating-Identity so extras is correct. (openshif…
Browse files Browse the repository at this point in the history
  • Loading branch information
shawn-hurley authored and Jay Boyd committed Jan 31, 2018
1 parent f358b99 commit 4d9be8f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 15 deletions.
2 changes: 1 addition & 1 deletion pkg/controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ const testOriginatingIdentityValue = `{
"username": "fakeusername",
"uid": "fakeuid",
"groups": ["fakegroup1"],
"fakekey": ["fakevalue"]
"extra": {"fakekey": ["fakevalue"]}
}`

var testOriginatingIdentity = &osb.OriginatingIdentity{
Expand Down
12 changes: 1 addition & 11 deletions pkg/controller/originating_identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,13 @@ import (

const (
originatingIdentityPlatform = "kubernetes"
originatingIdentityUsername = "username"
originatingIdentityUID = "uid"
originatingIdentityGroups = "groups"
)

func buildOriginatingIdentity(userInfo *v1beta1.UserInfo) (*osb.OriginatingIdentity, error) {
if userInfo == nil {
return nil, nil
}
oiFields := map[string]interface{}{}
oiFields[originatingIdentityUsername] = userInfo.Username
oiFields[originatingIdentityUID] = userInfo.UID
oiFields[originatingIdentityGroups] = userInfo.Groups
for k, v := range userInfo.Extra {
oiFields[k] = v
}
oiValue, err := json.Marshal(oiFields)
oiValue, err := json.Marshal(userInfo)
if err != nil {
return nil, err
}
Expand Down
30 changes: 27 additions & 3 deletions pkg/controller/originating_identity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ limitations under the License.
package controller

import (
"encoding/json"
"fmt"
"reflect"
"testing"

"github.com/kubernetes-incubator/service-catalog/pkg/apis/servicecatalog/v1beta1"
Expand All @@ -33,7 +36,7 @@ func TestBuildOriginatingIdentity(t *testing.T) {

e := osb.OriginatingIdentity{
Platform: "kubernetes",
Value: `{"foo":["bar","baz"],"groups":["stuff-dev","main-eng"],"uid":"abcd-1234","username":"person@place.com"}`,
Value: `{extra: {"foo":["bar","baz"]},"groups":["stuff-dev","main-eng"],"uid":"abcd-1234","username":"person@place.com"}`,
}

g, err := buildOriginatingIdentity(&userInfo)
Expand All @@ -46,7 +49,28 @@ func TestBuildOriginatingIdentity(t *testing.T) {
t.Fatalf("Unexpected Platform, %s", expectedGot(e.Platform, g.Platform))
}

if e.Value != g.Value {
t.Fatalf("Unexpected Value, %s", expectedGot(e.Value, g.Value))
var retUserInfo v1beta1.UserInfo
err = json.Unmarshal([]byte(g.Value), &retUserInfo)
if err != nil {
t.Fatalf("Unexpected Error, %+v", err)
}

if userInfo.Username != retUserInfo.Username {
t.Fatalf("Unexpected Value Username, %s", expectedGot(userInfo.Username, retUserInfo.Username))
}
if userInfo.UID != retUserInfo.UID {
t.Fatalf("Unexpected Value UID, %s", expectedGot(userInfo.UID, retUserInfo.UID))
}

if !reflect.DeepEqual(userInfo.Groups, retUserInfo.Groups) {
t.Fatalf("Unexpected Value Groups, %s", expectedGot(fmt.Sprintf("%#v", userInfo.Groups), fmt.Sprintf("%#v", retUserInfo.Groups)))
}

if extras, ok := retUserInfo.Extra["foo"]; !ok {
t.Fatalf("Unexpected Value extras, %s", expectedGot(fmt.Sprintf("%#v", userInfo.Extra), fmt.Sprintf("%#v", retUserInfo.Extra)))
} else {
if !reflect.DeepEqual(extras, userInfo.Extra["foo"]) {
t.Fatalf("Unexpected Value extras, %s", expectedGot(fmt.Sprintf("%#v", userInfo.Extra), fmt.Sprintf("%#v", retUserInfo.Extra)))
}
}
}

0 comments on commit 4d9be8f

Please sign in to comment.