| @@ 116-164 (lines=49) @@ | ||
| 113 | self.assertEqual(404, response.code) |
|
| 114 | ||
| 115 | ||
| 116 | class TestEndpointHandlerWithoutAuth(AsyncHTTPTestCase): |
|
| 117 | @classmethod |
|
| 118 | def setUpClass(cls): |
|
| 119 | _init_asyncio_patch() |
|
| 120 | prefix = "__TestEndpointHandlerWithoutAuth_" |
|
| 121 | ||
| 122 | # create state.ini dir and file |
|
| 123 | cls.state_dir = tempfile.mkdtemp(prefix=prefix) |
|
| 124 | cls.state_file = open(os.path.join(cls.state_dir, "state.ini"), "w+") |
|
| 125 | cls.state_file.write( |
|
| 126 | "[Service Info]\n" |
|
| 127 | "Name = TabPy Serve\n" |
|
| 128 | "Description = \n" |
|
| 129 | "Creation Time = 0\n" |
|
| 130 | "Access-Control-Allow-Origin = \n" |
|
| 131 | "Access-Control-Allow-Headers = \n" |
|
| 132 | "Access-Control-Allow-Methods = \n" |
|
| 133 | "\n" |
|
| 134 | "[Query Objects Service Versions]\n" |
|
| 135 | "\n" |
|
| 136 | "[Query Objects Docstrings]\n" |
|
| 137 | "\n" |
|
| 138 | "[Meta]\n" |
|
| 139 | "Revision Number = 1\n" |
|
| 140 | ) |
|
| 141 | cls.state_file.close() |
|
| 142 | ||
| 143 | @classmethod |
|
| 144 | def tearDownClass(cls): |
|
| 145 | os.remove(cls.state_file.name) |
|
| 146 | os.rmdir(cls.state_dir) |
|
| 147 | ||
| 148 | def get_app(self): |
|
| 149 | self.app = TabPyApp(None) |
|
| 150 | return self.app._create_tornado_web_app() |
|
| 151 | ||
| 152 | def test_creds_no_auth_fails(self): |
|
| 153 | response = self.fetch( |
|
| 154 | "/endpoints/", |
|
| 155 | method="GET", |
|
| 156 | headers={
|
|
| 157 | "Authorization": "Basic {}".format(
|
|
| 158 | base64.b64encode("username:password".encode("utf-8")).decode(
|
|
| 159 | "utf-8" |
|
| 160 | ) |
|
| 161 | ) |
|
| 162 | }, |
|
| 163 | ) |
|
| 164 | self.assertEqual(406, response.code) |
|
| 165 | ||
| @@ 99-146 (lines=48) @@ | ||
| 96 | self.assertEqual(200, response.code) |
|
| 97 | ||
| 98 | ||
| 99 | class TestEndpointsHandlerWithoutAuth(AsyncHTTPTestCase): |
|
| 100 | @classmethod |
|
| 101 | def setUpClass(cls): |
|
| 102 | prefix = "__TestEndpointsHandlerWithoutAuth_" |
|
| 103 | ||
| 104 | # create state.ini dir and file |
|
| 105 | cls.state_dir = tempfile.mkdtemp(prefix=prefix) |
|
| 106 | cls.state_file = open(os.path.join(cls.state_dir, "state.ini"), "w+") |
|
| 107 | cls.state_file.write( |
|
| 108 | "[Service Info]\n" |
|
| 109 | "Name = TabPy Serve\n" |
|
| 110 | "Description = \n" |
|
| 111 | "Creation Time = 0\n" |
|
| 112 | "Access-Control-Allow-Origin = \n" |
|
| 113 | "Access-Control-Allow-Headers = \n" |
|
| 114 | "Access-Control-Allow-Methods = \n" |
|
| 115 | "\n" |
|
| 116 | "[Query Objects Service Versions]\n" |
|
| 117 | "\n" |
|
| 118 | "[Query Objects Docstrings]\n" |
|
| 119 | "\n" |
|
| 120 | "[Meta]\n" |
|
| 121 | "Revision Number = 1\n" |
|
| 122 | ) |
|
| 123 | cls.state_file.close() |
|
| 124 | ||
| 125 | @classmethod |
|
| 126 | def tearDownClass(cls): |
|
| 127 | os.remove(cls.state_file.name) |
|
| 128 | os.rmdir(cls.state_dir) |
|
| 129 | ||
| 130 | def get_app(self): |
|
| 131 | self.app = TabPyApp(None) |
|
| 132 | return self.app._create_tornado_web_app() |
|
| 133 | ||
| 134 | def test_creds_no_auth_fails(self): |
|
| 135 | response = self.fetch( |
|
| 136 | "/endpoints", |
|
| 137 | method="GET", |
|
| 138 | headers={
|
|
| 139 | "Authorization": "Basic {}".format(
|
|
| 140 | base64.b64encode("username:password".encode("utf-8")).decode(
|
|
| 141 | "utf-8" |
|
| 142 | ) |
|
| 143 | ) |
|
| 144 | }, |
|
| 145 | ) |
|
| 146 | self.assertEqual(406, response.code) |
|
| 147 | ||