func TestOAuth2HandlerBeginAuthURLWithBaseWithoutState(t *testing.T) { common.SetSecurityKey("rAALj6QhRjsTo3VKzfWuK21qNZ5bFfqPJ9sYNerSYeKKoMIPAi9vaIusjmqyLE3S") base := "https://base.url/auth" config := &common.Config{Map: objx.MSI()} config. Set("client_id", "client_id"). Set("redirect_uri", "redirect_uri"). Set("scope", "scope"). Set("access_type", "access_type"). Set("approval_prompt", "approval_prompt") url, err := GetBeginAuthURLWithBase(base, nil, config) if assert.NoError(t, err) { assert.Contains(t, url, "client_id=client_id") assert.Contains(t, url, "redirect_uri=redirect_uri") assert.Contains(t, url, "scope=scope") assert.Contains(t, url, "access_type=access_type") assert.Contains(t, url, "approval_prompt=approval_prompt") assert.NotContains(t, url, "state=") } }
func TestspotifyGetBeginAuthURL(t *testing.T) { common.SetSecurityKey("ABC123") state := &common.State{Map: objx.MSI("after", "http://www.chikin14niwa.com/")} g := New("clientID", "secret", "http://myapp.com/") url, err := g.GetBeginAuthURL(state, nil) if assert.NoError(t, err) { assert.Contains(t, url, "client_id=clientID") assert.Contains(t, url, "redirect_uri=http%3A%2F%2Fmyapp.com%2F") assert.Contains(t, url, "scope="+spotifyDefaultScope) assert.Contains(t, url, "access_type="+oauth2.OAuth2AccessTypeOnline) assert.Contains(t, url, "approval_prompt="+oauth2.OAuth2ApprovalPromptAuto) } state = &common.State{Map: objx.MSI("after", "http://www.chikin14niwa.com/")} g = New("clientID", "secret", "http://myapp.com/") url, err = g.GetBeginAuthURL(state, objx.MSI(oauth2.OAuth2KeyScope, "avatar")) if assert.NoError(t, err) { assert.Contains(t, url, "client_id=clientID") assert.Contains(t, url, "redirect_uri=http%3A%2F%2Fmyapp.com%2F") assert.Contains(t, url, "scope=avatar+"+spotifyDefaultScope) assert.Contains(t, url, "access_type="+oauth2.OAuth2AccessTypeOnline) assert.Contains(t, url, "approval_prompt="+oauth2.OAuth2ApprovalPromptAuto) } }
func TestOAuth2HandlerBeginAuthURLWithBaseMultipleScope(t *testing.T) { common.SetSecurityKey("rAALj6QhRjsTo3VKzfWuK21qNZ5bFfqPJ9sYNerSYeKKoMIPAi9vaIusjmqyLE3S") base := "https://base.url/auth" config := &common.Config{Map: objx.MSI()} config. Set("client_id", "client_id"). Set("redirect_uri", "redirect_uri"). Set("scope", "scope1 scope2"). Set("access_type", "access_type"). Set("approval_prompt", "approval_prompt") state := &common.State{Map: objx.MSI("after", "http://www.chikin14niwa.com/")} base64State, _ := state.Base64() url, err := GetBeginAuthURLWithBase(base, state, config) if assert.NoError(t, err) { assert.Contains(t, url, "client_id=client_id") assert.Contains(t, url, "redirect_uri=redirect_uri") assert.Contains(t, url, "scope=scope1+scope2") assert.Contains(t, url, "access_type=access_type") assert.Contains(t, url, "approval_prompt=approval_prompt") assert.Contains(t, url, "state="+base64State) } }