1 package org.apache.archiva.web.test;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
22 import org.apache.archiva.web.test.parent.AbstractArchivaTest;
23 import org.testng.annotations.Test;
26 * Test all actions affected with CSRF security issue.
28 @Test( groups = { "csrf" }, dependsOnMethods = { "testWithCorrectUsernamePassword" }, sequential = true )
29 public class CSRFSecurityTest
30 extends AbstractArchivaTest
32 public void testCSRFDeleteRepository()
34 getSelenium().open( baseUrl );
35 getSelenium().open( baseUrl + "/admin/deleteRepository.action?repoid=test&method%3AdeleteContents=Delete+Configuration+and+Contents" );
36 assertTextPresent( "Security Alert - Invalid Token Found" );
37 assertTextPresent( "Possible CSRF attack detected! Invalid token found in the request." );
40 public void testCSRFDeleteArtifact()
42 getSelenium().open( baseUrl );
43 getSelenium().open( baseUrl + "/deleteArtifact!doDelete.action?groupId=1&artifactId=1&version=1&repositoryId=snapshots" );
44 assertTextPresent( "Security Alert - Invalid Token Found" );
45 assertTextPresent( "Possible CSRF attack detected! Invalid token found in the request." );
48 public void testCSRFAddRepositoryGroup()
50 getSelenium().open( baseUrl );
51 getSelenium().open( baseUrl + "/admin/addRepositoryGroup.action?repositoryGroup.id=csrfgrp" );
52 assertTextPresent( "Security Alert - Invalid Token Found" );
53 assertTextPresent( "Possible CSRF attack detected! Invalid token found in the request." );
56 public void testCSRFDeleteRepositoryGroup()
58 getSelenium().open( baseUrl );
59 getSelenium().open( baseUrl + "/admin/deleteRepositoryGroup.action?repoGroupId=test&method%3Adelete=Confirm" );
60 assertTextPresent( "Security Alert - Invalid Token Found" );
61 assertTextPresent( "Possible CSRF attack detected! Invalid token found in the request." );
64 public void testCSRFDisableProxyConnector()
66 getSelenium().open( baseUrl );
67 getSelenium().open( baseUrl + "/admin/disableProxyConnector!disable.action?target=maven2-repository.dev.java.net&source=internal" );
68 assertTextPresent( "Security Alert - Invalid Token Found" );
69 assertTextPresent( "Possible CSRF attack detected! Invalid token found in the request." );
72 public void testCSRFDeleteProxyConnector()
74 getSelenium().open( baseUrl );
75 getSelenium().open( baseUrl + "/admin/deleteProxyConnector!delete.action?target=maven2-repository.dev.java.net&source=snapshots" );
76 assertTextPresent( "Security Alert - Invalid Token Found" );
77 assertTextPresent( "Possible CSRF attack detected! Invalid token found in the request." );
80 public void testCSRFDeleteLegacyArtifactPath()
82 getSelenium().open( baseUrl );
83 getSelenium().open( baseUrl + "/admin/deleteLegacyArtifactPath.action?path=jaxen%2Fjars%2Fjaxen-1.0-FCS-full.jar" );
84 assertTextPresent( "Security Alert - Invalid Token Found" );
85 assertTextPresent( "Possible CSRF attack detected! Invalid token found in the request." );
88 public void testCSRFSaveNetworkProxy()
90 getSelenium().open( baseUrl );
91 getSelenium().open( baseUrl + "/admin/saveNetworkProxy.action?mode=add&proxy.id=ntwrk&proxy.protocol=http&" +
92 "proxy.host=test&proxy.port=8080&proxy.username=&proxy.password=" );
93 assertTextPresent( "Security Alert - Invalid Token Found" );
94 assertTextPresent( "Possible CSRF attack detected! Invalid token found in the request." );
97 public void testCSRFDeleteNetworkProxy()
99 getSelenium().open( baseUrl );
100 getSelenium().open( baseUrl + "/admin/deleteNetworkProxy!delete.action?proxyid=myproxy" );
101 assertTextPresent( "Security Alert - Invalid Token Found" );
102 assertTextPresent( "Possible CSRF attack detected! Invalid token found in the request." );
105 public void testCSRFAddFileTypePattern()
107 getSelenium().open( baseUrl );
108 getSelenium().open( baseUrl + "/admin/repositoryScanning!addFiletypePattern.action?pattern=**%2F*.rum&fileTypeId=artifacts" );
109 assertTextPresent( "Security Alert - Invalid Token Found" );
110 assertTextPresent( "Possible CSRF attack detected! Invalid token found in the request." );
113 public void testCSRFRemoveFileTypePattern()
115 getSelenium().open( baseUrl );
116 getSelenium().open( baseUrl + "/admin/repositoryScanning!removeFiletypePattern.action?pattern=**%2F*.rum&fileTypeId=artifacts" );
117 assertTextPresent( "Security Alert - Invalid Token Found" );
118 assertTextPresent( "Possible CSRF attack detected! Invalid token found in the request." );
121 public void testCSRFUpdateKnownConsumers()
123 getSelenium().open( baseUrl );
124 getSelenium().open( baseUrl + "/admin/repositoryScanning!updateKnownConsumers.action?enabledKnownContentConsumers=auto-remove&" +
125 "enabledKnownContentConsumers=auto-rename&enabledKnownContentConsumers=create-missing-checksums&" +
126 "enabledKnownContentConsumers=index-content&enabledKnownContentConsumers=metadata-updater&" +
127 "enabledKnownContentConsumers=repository-purge&enabledKnownContentConsumers=update-db-artifact&" +
128 "enabledKnownContentConsumers=validate-checksums" );
129 assertTextPresent( "Security Alert - Invalid Token Found" );
130 assertTextPresent( "Possible CSRF attack detected! Invalid token found in the request." );