@@ -111,3 +111,61 @@ func TestRateLimitJSON(t *testing.T) {
111111 t .Errorf ("Unexpected reason: %v\n " , re .RateLimitError .Reason )
112112 }
113113}
114+
115+ func TestAuthError (t * testing.T ) {
116+ eString := `{"error_summary": "user_suspended/...", "error": {".tag": "user_suspended"}}`
117+ ts := httptest .NewServer (http .HandlerFunc (
118+ func (w http.ResponseWriter , r * http.Request ) {
119+ w .Header ().Set ("Content-Type" , "application/json; charset=utf-8" )
120+ w .WriteHeader (http .StatusUnauthorized )
121+ w .Write ([]byte (eString ))
122+ }))
123+ defer ts .Close ()
124+
125+ config := dropbox.Config {Client : ts .Client (), LogLevel : dropbox .LogDebug ,
126+ URLGenerator : func (hostType string , style string , namespace string , route string ) string {
127+ return generateURL (ts .URL , namespace , route )
128+ }}
129+ client := users .New (config )
130+ _ , e := client .GetCurrentAccount ()
131+ re , ok := e .(auth.AuthAPIError )
132+ if ! ok {
133+ t .Errorf ("Unexpected error type: %T\n " , e )
134+ }
135+ fmt .Printf ("ERROR is %v\n " , re )
136+ if re .AuthError .Tag != auth .AuthErrorUserSuspended {
137+ t .Errorf ("Unexpected tag: %s\n " , re .AuthError .Tag )
138+ }
139+ }
140+
141+ func TestAccessError (t * testing.T ) {
142+ eString := `{"error_summary": "access_error/...",
143+ "error": {
144+ ".tag": "paper_access_denied",
145+ "paper_access_denied": {".tag": "not_paper_user"}
146+ }}`
147+ ts := httptest .NewServer (http .HandlerFunc (
148+ func (w http.ResponseWriter , r * http.Request ) {
149+ w .Header ().Set ("Content-Type" , "application/json; charset=utf-8" )
150+ w .WriteHeader (http .StatusForbidden )
151+ w .Write ([]byte (eString ))
152+ }))
153+ defer ts .Close ()
154+
155+ config := dropbox.Config {Client : ts .Client (), LogLevel : dropbox .LogDebug ,
156+ URLGenerator : func (hostType string , style string , namespace string , route string ) string {
157+ return generateURL (ts .URL , namespace , route )
158+ }}
159+ client := users .New (config )
160+ _ , e := client .GetCurrentAccount ()
161+ re , ok := e .(auth.AccessAPIError )
162+ if ! ok {
163+ t .Errorf ("Unexpected error type: %T\n " , e )
164+ }
165+ if re .AccessError .Tag != auth .AccessErrorPaperAccessDenied {
166+ t .Errorf ("Unexpected tag: %s\n " , re .AccessError .Tag )
167+ }
168+ if re .AccessError .PaperAccessDenied .Tag != auth .PaperAccessErrorNotPaperUser {
169+ t .Errorf ("Unexpected tag: %s\n " , re .AccessError .PaperAccessDenied .Tag )
170+ }
171+ }
0 commit comments