3 # ARVADOS_API_TOKEN=abc ARVADOS_API_HOST=arvados.local python -m unittest discover
11 class KeepTestCase(unittest.TestCase):
14 super(KeepTestCase, cls).setUpClass()
16 del os.environ['KEEP_LOCAL_STORE']
20 # Make sure these are clear, we want to talk to the Keep servers
22 os.environ["ARVADOS_KEEP_PROXY"] = ""
23 os.environ["ARVADOS_EXTERNAL_CLIENT"] = ""
26 run_test_server.run_keep()
27 arvados.keep.global_client_object = None
28 arvados.config._settings = None
29 run_test_server.authorize_with("admin")
32 def tearDownClass(cls):
33 super(KeepTestCase, cls).tearDownClass()
34 run_test_server.stop()
35 run_test_server.stop_keep()
37 def test_KeepBasicRWTest(self):
38 foo_locator = arvados.Keep.put('foo')
39 self.assertEqual(foo_locator,
40 'acbd18db4cc2f85cedef654fccc4a4d8+3',
41 'wrong md5 hash from Keep.put("foo"): ' + foo_locator)
42 self.assertEqual(arvados.Keep.get(foo_locator),
44 'wrong content from Keep.get(md5("foo"))')
46 def test_KeepBinaryRWTest(self):
47 blob_str = '\xff\xfe\xf7\x00\x01\x02'
48 blob_locator = arvados.Keep.put(blob_str)
49 self.assertEqual(blob_locator,
50 '7fc7c53b45e53926ba52821140fef396+6',
51 ('wrong locator from Keep.put(<binarydata>):' +
53 self.assertEqual(arvados.Keep.get(blob_locator),
55 'wrong content from Keep.get(md5(<binarydata>))')
57 def test_KeepLongBinaryRWTest(self):
58 blob_str = '\xff\xfe\xfd\xfc\x00\x01\x02\x03'
60 blob_str = blob_str + blob_str
61 blob_locator = arvados.Keep.put(blob_str)
62 self.assertEqual(blob_locator,
63 '84d90fc0d8175dd5dcfab04b999bc956+67108864',
64 ('wrong locator from Keep.put(<binarydata>): ' +
66 self.assertEqual(arvados.Keep.get(blob_locator),
68 'wrong content from Keep.get(md5(<binarydata>))')
70 def test_KeepSingleCopyRWTest(self):
71 blob_str = '\xff\xfe\xfd\xfc\x00\x01\x02\x03'
72 blob_locator = arvados.Keep.put(blob_str, copies=1)
73 self.assertEqual(blob_locator,
74 'c902006bc98a3eb4a3663b65ab4a6fab+8',
75 ('wrong locator from Keep.put(<binarydata>): ' +
77 self.assertEqual(arvados.Keep.get(blob_locator),
79 'wrong content from Keep.get(md5(<binarydata>))')
81 class KeepPermissionTestCase(unittest.TestCase):
85 del os.environ['KEEP_LOCAL_STORE']
90 run_test_server.run_keep(blob_signing_key='abcdefghijk0123456789',
91 enforce_permissions=True)
94 def tearDownClass(cls):
95 run_test_server.stop()
96 run_test_server.stop_keep()
98 def test_KeepBasicRWTest(self):
99 run_test_server.authorize_with('active')
100 foo_locator = arvados.Keep.put('foo')
101 self.assertRegexpMatches(
103 r'^acbd18db4cc2f85cedef654fccc4a4d8\+3\+A[a-f0-9]+@[a-f0-9]+$',
104 'invalid locator from Keep.put("foo"): ' + foo_locator)
105 self.assertEqual(arvados.Keep.get(foo_locator),
107 'wrong content from Keep.get(md5("foo"))')
109 # GET with an unsigned locator => NotFound
110 bar_locator = arvados.Keep.put('bar')
111 unsigned_bar_locator = "37b51d194a7513e45b56f6524f2d51f2+3"
112 self.assertRegexpMatches(
114 r'^37b51d194a7513e45b56f6524f2d51f2\+3\+A[a-f0-9]+@[a-f0-9]+$',
115 'invalid locator from Keep.put("bar"): ' + bar_locator)
116 self.assertRaises(arvados.errors.NotFoundError,
118 unsigned_bar_locator)
120 # GET from a different user => NotFound
121 run_test_server.authorize_with('spectator')
122 self.assertRaises(arvados.errors.NotFoundError,
126 # Unauthenticated GET for a signed locator => NotFound
127 # Unauthenticated GET for an unsigned locator => NotFound
128 del arvados.config.settings()["ARVADOS_API_TOKEN"]
129 self.assertRaises(arvados.errors.NotFoundError,
132 self.assertRaises(arvados.errors.NotFoundError,
134 unsigned_bar_locator)
136 # KeepOptionalPermission: starts Keep with --permission-key-file
137 # but not --enforce-permissions (i.e. generate signatures on PUT
138 # requests, but do not require them for GET requests)
140 # All of these requests should succeed when permissions are optional:
141 # * authenticated request, signed locator
142 # * authenticated request, unsigned locator
143 # * unauthenticated request, signed locator
144 # * unauthenticated request, unsigned locator
146 class KeepOptionalPermission(unittest.TestCase):
150 del os.environ['KEEP_LOCAL_STORE']
153 run_test_server.run()
154 run_test_server.run_keep(blob_signing_key='abcdefghijk0123456789',
155 enforce_permissions=False)
158 def tearDownClass(cls):
159 run_test_server.stop()
160 run_test_server.stop_keep()
162 def test_KeepAuthenticatedSignedTest(self):
163 run_test_server.authorize_with('active')
164 signed_locator = arvados.Keep.put('foo')
165 self.assertRegexpMatches(
167 r'^acbd18db4cc2f85cedef654fccc4a4d8\+3\+A[a-f0-9]+@[a-f0-9]+$',
168 'invalid locator from Keep.put("foo"): ' + signed_locator)
169 self.assertEqual(arvados.Keep.get(signed_locator),
171 'wrong content from Keep.get(md5("foo"))')
173 def test_KeepAuthenticatedUnsignedTest(self):
174 run_test_server.authorize_with('active')
175 signed_locator = arvados.Keep.put('foo')
176 self.assertRegexpMatches(
178 r'^acbd18db4cc2f85cedef654fccc4a4d8\+3\+A[a-f0-9]+@[a-f0-9]+$',
179 'invalid locator from Keep.put("foo"): ' + signed_locator)
180 self.assertEqual(arvados.Keep.get("acbd18db4cc2f85cedef654fccc4a4d8"),
182 'wrong content from Keep.get(md5("foo"))')
184 def test_KeepUnauthenticatedSignedTest(self):
185 # Since --enforce-permissions is not in effect, GET requests
186 # need not be authenticated.
187 run_test_server.authorize_with('active')
188 signed_locator = arvados.Keep.put('foo')
189 self.assertRegexpMatches(
191 r'^acbd18db4cc2f85cedef654fccc4a4d8\+3\+A[a-f0-9]+@[a-f0-9]+$',
192 'invalid locator from Keep.put("foo"): ' + signed_locator)
194 del arvados.config.settings()["ARVADOS_API_TOKEN"]
195 self.assertEqual(arvados.Keep.get(signed_locator),
197 'wrong content from Keep.get(md5("foo"))')
199 def test_KeepUnauthenticatedUnsignedTest(self):
200 # Since --enforce-permissions is not in effect, GET requests
201 # need not be authenticated.
202 run_test_server.authorize_with('active')
203 signed_locator = arvados.Keep.put('foo')
204 self.assertRegexpMatches(
206 r'^acbd18db4cc2f85cedef654fccc4a4d8\+3\+A[a-f0-9]+@[a-f0-9]+$',
207 'invalid locator from Keep.put("foo"): ' + signed_locator)
209 del arvados.config.settings()["ARVADOS_API_TOKEN"]
210 self.assertEqual(arvados.Keep.get("acbd18db4cc2f85cedef654fccc4a4d8"),
212 'wrong content from Keep.get(md5("foo"))')
215 class KeepProxyTestCase(unittest.TestCase):
218 super(KeepProxyTestCase, cls).setUpClass()
221 del os.environ['KEEP_LOCAL_STORE']
225 os.environ["ARVADOS_KEEP_PROXY"] = ""
226 os.environ["ARVADOS_EXTERNAL_CLIENT"] = ""
228 run_test_server.run()
229 run_test_server.run_keep()
230 arvados.keep.global_client_object = None
231 arvados.config._settings = None
232 run_test_server.run_keep_proxy("admin")
233 KeepProxyTestCase.arvados_keep_proxy = arvados.config.get("ARVADOS_KEEP_PROXY")
236 def tearDownClass(cls):
237 super(KeepProxyTestCase, cls).tearDownClass()
238 run_test_server.stop()
239 run_test_server.stop_keep()
240 run_test_server.stop_keep_proxy()
242 def test_KeepProxyTest1(self):
243 # Will use ARVADOS_KEEP_PROXY environment variable that is set by
244 # run_keep_proxy() in setUpClass()
246 os.environ["ARVADOS_KEEP_PROXY"] = KeepProxyTestCase.arvados_keep_proxy
247 os.environ["ARVADOS_EXTERNAL_CLIENT"] = ""
248 arvados.keep.global_client_object = None
249 arvados.config._settings = None
251 baz_locator = arvados.Keep.put('baz')
252 self.assertEqual(baz_locator,
253 '73feffa4b7f6bb68e44cf984c85f6e88+3',
254 'wrong md5 hash from Keep.put("baz"): ' + baz_locator)
255 self.assertEqual(arvados.Keep.get(baz_locator),
257 'wrong content from Keep.get(md5("baz"))')
259 self.assertEqual(True, arvados.Keep.global_client_object().using_proxy)
261 def test_KeepProxyTest2(self):
262 # We don't want to use ARVADOS_KEEP_PROXY from run_keep_proxy() in
263 # setUpClass(), so clear it and set ARVADOS_EXTERNAL_CLIENT which will
264 # contact the API server.
265 os.environ["ARVADOS_KEEP_PROXY"] = ""
266 os.environ["ARVADOS_EXTERNAL_CLIENT"] = "true"
267 arvados.keep.global_client_object = None
268 arvados.config._settings = None
270 # Will send X-External-Client to server and get back the proxy from
271 # keep_services/accessible
273 baz_locator = arvados.Keep.put('baz2')
274 self.assertEqual(baz_locator,
275 '91f372a266fe2bf2823cb8ec7fda31ce+4',
276 'wrong md5 hash from Keep.put("baz2"): ' + baz_locator)
277 self.assertEqual(arvados.Keep.get(baz_locator),
279 'wrong content from Keep.get(md5("baz2"))')
281 self.assertEqual(True, arvados.Keep.global_client_object().using_proxy)