private void assertSendContents(String contents, ResourceType type, String name) throws Exception { String path = getNamePath(type, name); HttpResponse response = doPostExternalAPI(path, contents, ADMIN_HEADERS); assertResponseStatus(response, HttpResponseStatus.OK); Reader reader = new InputStreamReader(response.getEntity().getContent()); ResourceMeta responseMeta = gson.fromJson(reader, ResourceMeta.class); Assert.assertEquals(name, responseMeta.getName()); Assert.assertEquals(ResourceStatus.INACTIVE, responseMeta.getStatus()); }
@Test public void testNonAdminGetsForbidden() throws Exception { ResourceType type1 = new ResourceType(PluginType.PROVIDER, "joyent", "keys"); ResourceType type2 = new ResourceType(PluginType.AUTOMATOR, "shell", "script"); ResourceMeta meta = new ResourceMeta("name", 1); assertResponseStatus(doPostExternalAPI(getNamePath(type1, "name"), "contents", USER1_HEADERS), HttpResponseStatus.FORBIDDEN); assertResponseStatus(doPostExternalAPI(getNamePath(type2, "name"), "contents", USER1_HEADERS), HttpResponseStatus.FORBIDDEN); assertResponseStatus(doDeleteExternalAPI(getVersionedPath(type1, meta), USER1_HEADERS), HttpResponseStatus.FORBIDDEN); assertResponseStatus(doDeleteExternalAPI(getVersionedPath(type2, meta), USER1_HEADERS), HttpResponseStatus.FORBIDDEN); assertResponseStatus(doGetExternalAPI(getNamePath(type1, "name"), USER1_HEADERS), HttpResponseStatus.FORBIDDEN); assertResponseStatus(doGetExternalAPI(getNamePath(type2, "name"), USER1_HEADERS), HttpResponseStatus.FORBIDDEN); assertResponseStatus(doGetExternalAPI(getTypePath(type1), USER1_HEADERS), HttpResponseStatus.FORBIDDEN); assertResponseStatus(doGetExternalAPI(getTypePath(type2), USER1_HEADERS), HttpResponseStatus.FORBIDDEN); }
private void testPutAndGet(PluginType type, String pluginName, String resourceType) throws Exception { String contents = RandomStringUtils.randomAlphanumeric(8 * Constants.PLUGIN_RESOURCE_CHUNK_SIZE); ResourceType pluginResourceType = new ResourceType(type, pluginName, resourceType); ResourceMeta meta = new ResourceMeta("hello", 1, ResourceStatus.INACTIVE); assertSendContents(contents, type, pluginName, resourceType, "hello"); // get metadata HttpResponse response = doGetExternalAPI(getNamePath(pluginResourceType, meta.getName()), ADMIN_HEADERS); assertResponseStatus(response, HttpResponseStatus.OK); Assert.assertEquals(ImmutableSet.of(meta), bodyToMetaSet(response)); // get actual contents String typeStr = type.name().toLowerCase() + "types"; String path = Joiner.on('/').join( "/tenants", ADMIN_ACCOUNT.getTenantId(), typeStr, pluginName, resourceType, meta.getName(), "versions", meta.getVersion() ); response = doGetInternalAPI(path); assertResponseStatus(response, HttpResponseStatus.OK); Assert.assertEquals(contents, bodyToString(response)); }
HttpResponseStatus.OK); HttpResponse response = doGetExternalAPI(getNamePath(pluginResourceType, meta2.getName()), ADMIN_HEADERS); assertResponseStatus(response, HttpResponseStatus.OK); Assert.assertEquals(Sets.newHashSet(meta1, meta2), bodyToMetaSet(response)); ); response = doGetExternalAPI(getNamePath(pluginResourceType, meta2.getName()) + "?status=staged", ADMIN_HEADERS); assertResponseStatus(response, HttpResponseStatus.OK); Assert.assertEquals(Sets.newHashSet(meta2), bodyToMetaSet(response)); response = doGetExternalAPI(getNamePath(pluginResourceType, meta1.getName()), ADMIN_HEADERS); assertResponseStatus(response, HttpResponseStatus.OK); Assert.assertEquals(Sets.newHashSet(meta1, meta2), bodyToMetaSet(response)); response = doGetExternalAPI(getNamePath(pluginResourceType, meta1.getName()) + "?status=staged", ADMIN_HEADERS); assertResponseStatus(response, HttpResponseStatus.OK); Assert.assertEquals(Sets.newHashSet(meta1), bodyToMetaSet(response)); response = doGetExternalAPI(getNamePath(pluginResourceType, meta1.getName()), ADMIN_HEADERS); assertResponseStatus(response, HttpResponseStatus.OK); Assert.assertEquals(ImmutableSet.<ResourceMeta>of(meta1, meta2), bodyToMetaSet(response)); response = doGetExternalAPI(getNamePath(pluginResourceType, meta1.getName()) + "?status=staged", ADMIN_HEADERS); assertResponseStatus(response, HttpResponseStatus.OK); Assert.assertTrue(bodyToMetaSet(response).isEmpty());