private String getVersionedPath(ResourceType type, String name, int version) { return Joiner.on("/").join(getTypePath(type), name, "versions", version); }
private String getNamePath(ResourceType type, String name) { return Joiner.on("/").join(getTypePath(type), name); }
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) ); }
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);
@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); }
Assert.assertEquals(Sets.newHashSet(meta1, meta2), bodyToMetaSet(response)); response = doGetExternalAPI(getTypePath(pluginResourceType) + "?status=staged", ADMIN_HEADERS); assertResponseStatus(response, HttpResponseStatus.OK); Assert.assertEquals( Assert.assertEquals(Sets.newHashSet(meta1, meta2), bodyToMetaSet(response)); response = doGetExternalAPI(getTypePath(pluginResourceType) + "?status=staged", ADMIN_HEADERS); assertResponseStatus(response, HttpResponseStatus.OK); Assert.assertEquals( Assert.assertEquals(ImmutableSet.<ResourceMeta>of(meta1, meta2), bodyToMetaSet(response)); response = doGetExternalAPI(getTypePath(pluginResourceType) + "?status=staged", ADMIN_HEADERS); assertResponseStatus(response, HttpResponseStatus.OK); Assert.assertTrue(bodyToMetaMap(response).isEmpty());