func (uv *UAAVerifier) Membership(user goth.User, c *http.Client) (map[string]interface{}, error) { var filterGroups []string for _, g := range uv.Groups { filterGroups = append(filterGroups, fmt.Sprintf("displayName=%%22%s%%22", g)) } filter := strings.Join(filterGroups, "+or+") botta.SetClient(c) req, err := botta.Get(fmt.Sprintf("%s/Groups?attributes=displayName,members&filter=%s", uv.UAA, filter)) if err != nil { return nil, err } resp, err := botta.Issue(req) if err != nil { return nil, err } groups, err := resp.ArrayVal("resources") if err != nil { return nil, err } var membership []string for _, g := range groups { group, ok := g.(map[string]interface{}) if !ok { return nil, fmt.Errorf("Unexpected data type for group returned from UAA: %#v", g) } name, ok := group["displayName"].(string) if !ok { return nil, fmt.Errorf("Unexpected data type for group name returned form UAA: %#v", g) } members, ok := group["members"].([]interface{}) if !ok { return nil, fmt.Errorf("Unexpected data type for group membership returned from UAA: %#v", group["members"]) } for _, m := range members { member, ok := m.(map[string]interface{}) if !ok { return nil, fmt.Errorf("Unexpected data type for group member returned from UAA: %#v", m) } uid, ok := member["value"].(string) if !ok { return nil, fmt.Errorf("Unexpected data type for group member uid returned from UAA: %#v", member) } if uid == user.UserID { membership = append(membership, name) } } } return map[string]interface{}{"Groups": membership}, nil }
wd, err := os.Getwd() Expect(err).ShouldNot(HaveOccurred()) server = httptest.NewServer(http.FileServer(http.Dir(wd + "/assets"))) }) AfterEach(func() { if server != nil { server.Close() } }) var GET = func(path string, shouldSucceed bool) (*botta.Response, error) { req, err := botta.Get(server.URL + path) Expect(err).ShouldNot(HaveOccurred()) Expect(req).ShouldNot(BeNil()) resp, err := botta.Issue(req) if shouldSucceed { Expect(err).ShouldNot(HaveOccurred()) Expect(resp).ShouldNot(BeNil()) } else { Expect(err).Should(HaveOccurred()) } return resp, err } Context("Issue()", func() { It("should return errors from http.Client.Do()", func() { resp, err := botta.Issue(&http.Request{}) Expect(err).Should(HaveOccurred()) Expect(resp).Should(BeNil()) })