@Test public void testCallNonexistentResourceReturns404() throws Exception { List<String> getPaths = ImmutableList.of( // test nonexistent plugin "/plugins/providertypes/nonexistent/keys", "/plugins/automatortypes/nonexistent/cookbooks", // test nonexistent plugin resource type "/plugins/providertypes/joyent/cookbooks", "/plugins/automatortypes/chef-solo/keys" ); for (String getPath : getPaths) { assertResponseStatus(doGetExternalAPI(getPath, ADMIN_HEADERS), HttpResponseStatus.NOT_FOUND); } }
@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 testGetAndDelete(ResourceType type) throws Exception { String contents = "some contents"; ResourceMeta meta1 = new ResourceMeta("name1", 1, ResourceStatus.INACTIVE); ResourceMeta meta2 = new ResourceMeta("name1", 2, ResourceStatus.INACTIVE); ResourceMeta meta3 = new ResourceMeta("name2", 1, ResourceStatus.INACTIVE); ResourceMeta meta4 = new ResourceMeta("name3", 1, ResourceStatus.INACTIVE); assertSendContents(contents, type, meta1.getName()); assertSendContents(contents, type, meta2.getName()); assertSendContents(contents, type, meta3.getName()); assertSendContents(contents, type, meta4.getName()); HttpResponse response = doGetExternalAPI(getTypePath(type), ADMIN_HEADERS); assertResponseStatus(response, HttpResponseStatus.OK); Assert.assertEquals( ImmutableMap.<String, Set<ResourceMeta>>of( "name1", ImmutableSet.<ResourceMeta>of(meta1, meta2), "name2", ImmutableSet.<ResourceMeta>of(meta3), "name3", ImmutableSet.<ResourceMeta>of(meta4)), bodyToMetaMap(response) ); // delete one assertResponseStatus(doDeleteExternalAPI(getVersionedPath(type, meta3), ADMIN_HEADERS), HttpResponseStatus.OK); response = doGetExternalAPI(getTypePath(type), ADMIN_HEADERS); assertResponseStatus(response, HttpResponseStatus.OK); Assert.assertEquals( ImmutableMap.<String, Set<ResourceMeta>>of( "name1", ImmutableSet.<ResourceMeta>of(meta1, meta2), "name3", ImmutableSet.<ResourceMeta>of(meta4)), bodyToMetaMap(response) ); }
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)); }
HttpResponse response = doGetExternalAPI(getNamePath(pluginResourceType, meta2.getName()), ADMIN_HEADERS); assertResponseStatus(response, HttpResponseStatus.OK); Assert.assertEquals(Sets.newHashSet(meta1, meta2), bodyToMetaSet(response)); response = doGetExternalAPI(getTypePath(pluginResourceType) + "?status=staged", ADMIN_HEADERS); assertResponseStatus(response, HttpResponseStatus.OK); Assert.assertEquals( 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(getTypePath(pluginResourceType) + "?status=staged", ADMIN_HEADERS); assertResponseStatus(response, HttpResponseStatus.OK); Assert.assertEquals( 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(getTypePath(pluginResourceType) + "?status=staged", ADMIN_HEADERS);
HttpResponse response = doGetExternalAPI(getTypePath(cookbooks), ADMIN_HEADERS); assertResponseStatus(response, HttpResponseStatus.OK); Map<String, Set<ResourceMeta>> actual = bodyToMetaMap(response); Assert.assertEquals(expected, actual); response = doGetExternalAPI(getTypePath(keys), ADMIN_HEADERS); assertResponseStatus(response, HttpResponseStatus.OK); actual = bodyToMetaMap(response); response = doGetExternalAPI(getTypePath(cookbooks), ADMIN_HEADERS); assertResponseStatus(response, HttpResponseStatus.OK); actual = bodyToMetaMap(response); response = doGetExternalAPI(getTypePath(cookbooks), ADMIN_HEADERS); assertResponseStatus(response, HttpResponseStatus.OK); actual = bodyToMetaMap(response);