Mercurial > hg > tc-symbol-server
changeset 72:680794336d02 8.1.x
dropped duplicate test classes
author | Evgeniy.Koshkin |
---|---|
date | Thu, 27 Feb 2014 20:01:26 +0400 |
parents | 0da1c245f7a4 |
children | fd2005a04e4e |
files | server-tests/src/DownloadSymbolsControllerTest.java server-tests/src/MetadataStorageMock.java server-tests/src/jetbrains/buildServer/symbols/DownloadSymbolsControllerTest.java |
diffstat | 3 files changed, 22 insertions(+), 160 deletions(-) [+] |
line wrap: on
line diff
--- a/server-tests/src/DownloadSymbolsControllerTest.java Thu Feb 27 12:10:05 2014 +0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,112 +0,0 @@ -/* - * Copyright 2000-2013 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import jetbrains.buildServer.controllers.AuthorizationInterceptor; -import jetbrains.buildServer.controllers.BaseController; -import jetbrains.buildServer.controllers.BaseControllerTestCase; -import jetbrains.buildServer.controllers.interceptors.auth.HttpAuthenticationManager; -import jetbrains.buildServer.serverSide.RunningBuildEx; -import jetbrains.buildServer.serverSide.auth.Permission; -import jetbrains.buildServer.serverSide.auth.RoleScope; -import jetbrains.buildServer.symbols.AuthHelper; -import jetbrains.buildServer.symbols.DownloadSymbolsController; -import jetbrains.buildServer.users.SUser; -import org.apache.commons.httpclient.HttpStatus; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - -import java.io.File; -import java.io.IOException; - -/** - * @author Evgeniy.Koshkin - */ -public class DownloadSymbolsControllerTest extends BaseControllerTestCase { - - private MetadataStorageMock myBuildMetadataStorage; - - @Override - @BeforeMethod - public void setUp() throws Exception { - myBuildMetadataStorage = new MetadataStorageMock(); - super.setUp(); - myFixture.getServerSettings().setGuestLoginAllowed(true); - } - - @Override - protected BaseController createController() throws IOException { - AuthorizationInterceptor authInterceptor = myFixture.getSingletonService(AuthorizationInterceptor.class); - AuthHelper authHelper = new AuthHelper(myFixture.getServerSettings(), myFixture.getUserModel(), myFixture.getSingletonService(HttpAuthenticationManager.class)); - return new DownloadSymbolsController(myServer, myWebManager, authInterceptor, myFixture.getSecurityContext(), myBuildMetadataStorage, authHelper); - } - - @Test - public void request_pdb_simple() throws Throwable { - myFixture.getServerSettings().setPerProjectPermissionsEnabled(true); - SUser user = myFixture.getUserModel().getGuestUser(); - user.addRole(RoleScope.projectScope(myProject.getProjectId()), getProjectDevRole()); - assertTrue(user.isPermissionGrantedForProject(myProject.getProjectId(), Permission.VIEW_BUILD_RUNTIME_DATA)); - - myRequest.setRequestURI("mock", getRegisterPdbUrl("secur32.pdb", "8EF4E863187C45E78F4632152CC82FEB")); - doGet(); - assertEquals(HttpStatus.SC_OK, myResponse.getStatus()); - } - - @Test - public void request_pdb_two_slashes_in_url() throws Exception { - myRequest.setRequestURI("mock", "/app/symbols//index2.txt'"); - doGet(); - assertEquals(HttpStatus.SC_NOT_FOUND, myResponse.getStatus()); - } - - @Test - public void request_pdb_invalid_url() throws Exception { - myRequest.setRequestURI("mock", "/app/symbols/foo"); - doGet(); - assertEquals(HttpStatus.SC_NOT_FOUND, myResponse.getStatus()); - } - - @Test - public void request_not_existent_pdb() throws Exception { - myRequest.setRequestURI("mock", "/app/symbols/fileName/FileId2/fileName"); - doGet(); - assertEquals(HttpStatus.SC_NOT_FOUND, myResponse.getStatus()); - } - - @Test - public void request_pdb_unauthorized() throws Exception { - myFixture.getServerSettings().setGuestLoginAllowed(false); - myRequest.setRequestURI("mock", getRegisterPdbUrl("secur32.pdb", "8EF4E863187C45E78F4632152CC82FEB")); - doGet(); - assertEquals(HttpStatus.SC_UNAUTHORIZED, myResponse.getStatus()); - } - - @Test - public void request_pdb_no_permissions_granted() throws Exception { - myRequest.setRequestURI("mock", getRegisterPdbUrl("secur32.pdb", "8EF4E863187C45E78F4632152CC82FEB")); - doGet(); - assertEquals(HttpStatus.SC_UNAUTHORIZED, myResponse.getStatus()); - } - - private String getRegisterPdbUrl(String fileName, String fileSignature) throws IOException { - final File artDirectory = createTempDir(); - new File(artDirectory, "foo").createNewFile(); - myBuildType.setArtifactPaths(artDirectory.getAbsolutePath()); - RunningBuildEx build = startBuild(); - myBuildMetadataStorage.addEntry(build.getBuildId(), fileName, fileSignature); - return String.format("/app/symbols/%s/%s/%s", fileName, fileSignature, fileName); - } -}
--- a/server-tests/src/MetadataStorageMock.java Thu Feb 27 12:10:05 2014 +0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,47 +0,0 @@ -import jetbrains.buildServer.serverSide.metadata.BuildMetadataEntry; -import jetbrains.buildServer.serverSide.metadata.MetadataStorage; -import jetbrains.buildServer.symbols.BuildSymbolsIndexProvider; -import org.jetbrains.annotations.NotNull; - -import java.util.*; - -class MetadataStorageMock implements MetadataStorage { - - private List<BuildMetadataEntry> myEntries = new ArrayList<BuildMetadataEntry>(); - - public void addEntry(final long buildId, final String fileName, final String fileSignature) { - myEntries.add(new BuildMetadataEntry() { - public long getBuildId() { - return buildId; - } - - @NotNull - public String getKey() { - return fileSignature; - } - - @NotNull - public Map<String, String> getMetadata() { - HashMap<String, String> map = new HashMap<String, String>(); - map.put(BuildSymbolsIndexProvider.ARTIFACT_PATH_KEY, "foo"); - map.put(BuildSymbolsIndexProvider.FILE_NAME_KEY, fileName); - return map; - } - }); - } - - @NotNull - public Iterator<BuildMetadataEntry> getAllEntries(@NotNull String s) { - return myEntries.iterator(); - } - - @NotNull - public Iterator<BuildMetadataEntry> getEntriesByKey(@NotNull String s, @NotNull String s2) { - return myEntries.iterator(); - } - - @NotNull - public Iterator<BuildMetadataEntry> getBuildEntry(long l, @NotNull String s) { - return myEntries.iterator(); - } -} \ No newline at end of file
--- a/server-tests/src/jetbrains/buildServer/symbols/DownloadSymbolsControllerTest.java Thu Feb 27 12:10:05 2014 +0400 +++ b/server-tests/src/jetbrains/buildServer/symbols/DownloadSymbolsControllerTest.java Thu Feb 27 20:01:26 2014 +0400 @@ -1,4 +1,18 @@ -package jetbrains.buildServer.symbols; +package jetbrains.buildServer.symbols;/* + * Copyright 2000-2013 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ import jetbrains.buildServer.controllers.AuthorizationInterceptor; import jetbrains.buildServer.controllers.BaseController; @@ -50,6 +64,13 @@ } @Test + public void request_pdb_two_slashes_in_url() throws Exception { + myRequest.setRequestURI("mock", "/app/symbols//index2.txt'"); + doGet(); + assertEquals(HttpStatus.SC_NOT_FOUND, myResponse.getStatus()); + } + + @Test public void request_pdb_invalid_url() throws Exception { myRequest.setRequestURI("mock", "/app/symbols/foo"); doGet();