10 "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/sessions"
11 . "github.com/onsi/gomega"
14func testAtlassianBackend(status int, body string) *httptest.Server {
15 return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
16 if r.URL.Path != "/me" || r.Header.Get("Authorization") != "Bearer imaginary_access_token" {
17 w.WriteHeader(http.StatusUnauthorized)
21 _, _ = w.Write([]byte(body))
25func testAtlassianProvider(backend *httptest.Server) *AtlassianProvider {
26 p := NewAtlassianProvider(&ProviderData{})
27 u, _ := url.Parse(backend.URL)
28 updateURL(p.ProfileURL, u.Host)
29 updateURL(p.ValidateURL, u.Host)
33func TestNewAtlassianProvider(t *testing.T) {
36 providerData := NewAtlassianProvider(&ProviderData{}).Data()
37 g.Expect(providerData.ProviderName).To(Equal("Atlassian"))
38 g.Expect(providerData.LoginURL.String()).To(Equal("https://auth.atlassian.com/authorize"))
39 g.Expect(providerData.RedeemURL.String()).To(Equal("https://auth.atlassian.com/oauth/token"))
40 g.Expect(providerData.ProfileURL.String()).To(Equal("https://api.atlassian.com/me"))
41 g.Expect(providerData.ValidateURL.String()).To(Equal("https://api.atlassian.com/me"))
42 g.Expect(providerData.Scope).To(Equal("read:me"))
45func TestAtlassianProviderGetLoginURL(t *testing.T) {
47 p := NewAtlassianProvider(&ProviderData{ClientID: "client"})
49 loginURL, err := url.Parse(p.GetLoginURL("https://proxy/oauth2/callback", "state", "",
50 url.Values{"approval_prompt": {"force"}}))
51 g.Expect(err).ToNot(HaveOccurred())
54 g.Expect(q.Get("audience")).To(Equal("api.atlassian.com"))
55 g.Expect(q.Get("prompt")).To(Equal("consent"))
56 g.Expect(q.Has("approval_prompt")).To(BeFalse())
57 g.Expect(q.Get("scope")).To(Equal("read:me"))
59 loginURL, err = url.Parse(p.GetLoginURL("https://proxy/oauth2/callback", "state", "",
60 url.Values{"prompt": {"login"}}))
61 g.Expect(err).ToNot(HaveOccurred())
62 g.Expect(loginURL.Query().Get("prompt")).To(Equal("login"))
65func TestAtlassianProviderEnrichSession(t *testing.T) {
67 b := testAtlassianBackend(http.StatusOK, `{"account_id":"abc","email":"user@example.com"}`)
69 p := testAtlassianProvider(b)
71 session := CreateAuthorizedSession()
72 g.Expect(p.EnrichSession(context.Background(), session)).To(Succeed())
73 g.Expect(session.Email).To(Equal("user@example.com"))
76func TestAtlassianProviderEnrichSessionWithoutEmail(t *testing.T) {
78 b := testAtlassianBackend(http.StatusOK, `{"account_id":"abc"}`)
80 p := testAtlassianProvider(b)
82 g.Expect(p.EnrichSession(context.Background(), CreateAuthorizedSession())).ToNot(Succeed())
85func TestAtlassianProviderValidateSession(t *testing.T) {
87 b := testAtlassianBackend(http.StatusOK, `{"email":"user@example.com"}`)
89 p := testAtlassianProvider(b)
91 g.Expect(p.ValidateSession(context.Background(), CreateAuthorizedSession())).To(BeTrue())
92 g.Expect(p.ValidateSession(context.Background(), &sessions.SessionState{AccessToken: "wrong"})).To(BeFalse())
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list