-
Notifications
You must be signed in to change notification settings - Fork 609
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #213 from kevin-cantwell/master
fill in all dropbox user details and raw data
- Loading branch information
Showing
2 changed files
with
118 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
package dropbox | ||
|
||
import ( | ||
"net/http" | ||
"net/http/httptest" | ||
"os" | ||
"testing" | ||
|
||
|
@@ -45,6 +47,41 @@ func Test_BeginAuth(t *testing.T) { | |
a.Contains(s.AuthURL, "www.dropbox.com/oauth2/authorize") | ||
} | ||
|
||
func Test_FetchUser(t *testing.T) { | ||
accountPath := "/2/users/get_current_account" | ||
|
||
t.Parallel() | ||
a := assert.New(t) | ||
p := provider() | ||
|
||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
a.Equal(r.Header.Get("Authorization"), "Bearer 1234567890") | ||
a.Equal(r.Method, "POST") | ||
a.Equal(r.URL.Path, accountPath) | ||
w.Write([]byte(testAccountResponse)) | ||
})) | ||
p.AccountURL = ts.URL + accountPath | ||
|
||
// AuthURL is superfluous for this test but ok | ||
session, err := p.UnmarshalSession(`{"AuthURL":"https://www.dropbox.com/oauth2/authorize","Token":"1234567890"}`) | ||
a.NoError(err) | ||
user, err := p.FetchUser(session) | ||
a.NoError(err) | ||
a.Equal(user.UserID, "dbid:AAH4f99T0taONIb-OurWxbNQ6ywGRopQngc") | ||
a.Equal(user.FirstName, "Franz") | ||
a.Equal(user.LastName, "Ferdinand") | ||
a.Equal(user.Name, "Franz Ferdinand") | ||
a.Equal(user.Description, "Franz Ferdinand (Personal)") | ||
a.Equal(user.NickName, "[email protected]") | ||
a.Equal(user.Email, "[email protected]") | ||
a.Equal(user.Location, "US") | ||
a.Equal(user.AccessToken, "1234567890") | ||
a.Equal(user.AccessTokenSecret, "") | ||
a.Equal(user.AvatarURL, "https://dl-web.dropbox.com/account_photo/get/dbid%3AAAH4f99T0taONIb-OurWxbNQ6ywGRopQngc?vers=1453416673259\u0026size=128x128") | ||
a.Equal(user.Provider, "dropbox") | ||
a.Len(user.RawData, 14) | ||
} | ||
|
||
func Test_SessionFromJSON(t *testing.T) { | ||
t.Parallel() | ||
a := assert.New(t) | ||
|
@@ -79,3 +116,51 @@ func Test_GetAuthURL(t *testing.T) { | |
url, _ := s.GetAuthURL() | ||
a.Equal(url, "/foo") | ||
} | ||
|
||
var testAccountResponse = ` | ||
{ | ||
"account_id": "dbid:AAH4f99T0taONIb-OurWxbNQ6ywGRopQngc", | ||
"name": { | ||
"given_name": "Franz", | ||
"surname": "Ferdinand", | ||
"familiar_name": "Franz", | ||
"display_name": "Franz Ferdinand (Personal)", | ||
"abbreviated_name": "FF" | ||
}, | ||
"email": "[email protected]", | ||
"email_verified": true, | ||
"disabled": false, | ||
"locale": "en", | ||
"referral_link": "https://db.tt/ZITNuhtI", | ||
"is_paired": true, | ||
"account_type": { | ||
".tag": "business" | ||
}, | ||
"root_info": { | ||
".tag": "user", | ||
"root_namespace_id": "3235641", | ||
"home_namespace_id": "3235641" | ||
}, | ||
"country": "US", | ||
"team": { | ||
"id": "dbtid:AAFdgehTzw7WlXhZJsbGCLePe8RvQGYDr-I", | ||
"name": "Acme, Inc.", | ||
"sharing_policies": { | ||
"shared_folder_member_policy": { | ||
".tag": "team" | ||
}, | ||
"shared_folder_join_policy": { | ||
".tag": "from_anyone" | ||
}, | ||
"shared_link_create_policy": { | ||
".tag": "team_only" | ||
} | ||
}, | ||
"office_addin_policy": { | ||
".tag": "disabled" | ||
} | ||
}, | ||
"profile_photo_url": "https://dl-web.dropbox.com/account_photo/get/dbid%3AAAH4f99T0taONIb-OurWxbNQ6ywGRopQngc?vers=1453416673259\u0026size=128x128", | ||
"team_member_id": "dbmid:AAHhy7WsR0x-u4ZCqiDl5Fz5zvuL3kmspwU" | ||
} | ||
` |