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 }
Expect(req).ShouldNot(BeNil()) Expect(req.Method).Should(Equal("GET")) Expect(req.URL.String()).Should(Equal("https://localhost:1234/test")) req, err = botta.HttpRequest("POST", "https://myhost:1234/stuff", "ping") Expect(err).ShouldNot(HaveOccurred()) Expect(req).ShouldNot(BeNil()) Expect(req.Method).Should(Equal("POST")) Expect(req.URL.String()).Should(Equal("https://myhost:1234/stuff")) }) }) Context("Get()", func() { It("should create a GET http.Request", func() { req, err := botta.Get("https://localhost:1234/get") Expect(err).ShouldNot(HaveOccurred()) Expect(req).ShouldNot(BeNil()) Expect(req.Method).Should(Equal("GET")) Expect(req.URL.String()).Should(Equal("https://localhost:1234/get")) expect_body(req, "") }) It("should return an error if unsuccessful", func() { req, err := botta.Get("%") Expect(err).Should(HaveOccurred()) Expect(req).Should(BeNil()) }) }) Context("Post()", func() { It("should create a POST http.Request", func() { req, err := botta.Post("https://localhost:1234/post", "teststring")