Anonymous avatar Anonymous committed e27da87

add test in case authentification is bad.

Comments (0)

Files changed (3)

restclient/rest.py

 
             if self.status_code == 404:
                 raise ResourceNotFound(error)
-            elif self.status_code == 401:
+            elif self.status_code == 401 or self.status_code == 403:
                 raise Unauthorized
             else:
                 raise RequestFailed((self.status_code, error))

tests/_server_test.py

             else:
                 auth = self.headers['Authorization'][len('Basic')+1:]
                 auth = base64.b64decode(auth).split(':')
-                self._respond(200, extra_headers, "ok")
+                if auth[0] == "test" and auth[1] == "test":
+                    self._respond(200, extra_headers, "ok")
+                else:
+                    self._respond(403, extra_headers, "niet!")
         else:
             self._respond(404, 
                 [('Content-type', 'text/plain')], "Not Found" )

tests/clients_test.py

 from restclient.http import Urllib2HTTPClient, CurlHTTPClient, \
 HTTPLib2HTTPClient
 from restclient.rest import Resource, RestClient, RequestFailed, \
-ResourceNotFound
+ResourceNotFound, Unauthorized
 from _server_test import HOST, PORT
 
 class HTTPClientTestCase(unittest.TestCase):
         result = res.get('/auth')
         self.assert_(res.status_code == 200)
 
+        httpclient.add_credentials("test", "test2")
+        
+        def niettest():
+            res = Resource(self.url, httpclient)
+            result = res.get('/auth')
+        self.assertRaises(Unauthorized, niettest)
+
 
 
 class HTTPLib2HTTPClientTestCase(HTTPClientTestCase):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.