1 package org.apache.archiva.rest.services;
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
21 import org.apache.archiva.admin.model.beans.FileType;
22 import org.apache.archiva.admin.model.beans.OrganisationInformation;
23 import org.apache.archiva.admin.model.beans.UiConfiguration;
24 import org.apache.archiva.rest.api.model.AdminRepositoryConsumer;
25 import org.apache.archiva.rest.api.services.ArchivaRestServiceException;
26 import org.apache.commons.lang3.StringUtils;
27 import org.junit.Test;
29 import javax.ws.rs.BadRequestException;
30 import java.util.Arrays;
31 import java.util.List;
34 * @author Olivier Lamy
36 public class ArchivaAdministrationServiceTest
37 extends AbstractArchivaRestTest
40 public void getAllLegacyPaths()
43 assertNotNull( getArchivaAdministrationService().getLegacyArtifactPaths() );
44 assertFalse( getArchivaAdministrationService().getLegacyArtifactPaths().isEmpty() );
48 public void addAndDeleteFileType()
51 int initialSize = getArchivaAdministrationService().getFileTypes().size();
52 FileType fileType = new FileType();
53 fileType.setId( "footwo" );
54 fileType.setPatterns( Arrays.asList( "foo", "bar" ) );
55 getArchivaAdministrationService().addFileType( fileType );
56 assertEquals( initialSize + 1, getArchivaAdministrationService().getFileTypes().size() );
58 assertNotNull( getArchivaAdministrationService().getFileType( "footwo" ) );
59 assertEquals( Arrays.asList( "foo", "bar" ),
60 getArchivaAdministrationService().getFileType( "footwo" ).getPatterns() );
62 getArchivaAdministrationService().removeFileType( "footwo" );
64 assertEquals( initialSize, getArchivaAdministrationService().getFileTypes().size() );
66 assertNull( getArchivaAdministrationService().getFileType( "footwo" ) );
70 public void organisationInformationUpdate()
73 OrganisationInformation organisationInformation =
74 getArchivaAdministrationService().getOrganisationInformation();
76 // rest return an empty bean
77 assertNotNull( organisationInformation );
78 assertTrue( StringUtils.isBlank( organisationInformation.getLogoLocation() ) );
79 assertTrue( StringUtils.isBlank( organisationInformation.getName() ) );
80 assertTrue( StringUtils.isBlank( organisationInformation.getUrl() ) );
82 organisationInformation = new OrganisationInformation();
83 organisationInformation.setLogoLocation( "http://foo.com/bar.png" );
84 organisationInformation.setName( "foo org" );
85 organisationInformation.setUrl( "http://foo.com" );
87 getArchivaAdministrationService().setOrganisationInformation( organisationInformation );
89 organisationInformation = getArchivaAdministrationService().getOrganisationInformation();
90 assertNotNull( organisationInformation );
91 assertEquals( "http://foo.com/bar.png", organisationInformation.getLogoLocation() );
92 assertEquals( "foo org", organisationInformation.getName() );
93 assertEquals( "http://foo.com", organisationInformation.getUrl() );
97 public void badOrganizationLogoLocation()
100 OrganisationInformation organisationInformation =
101 getArchivaAdministrationService().getOrganisationInformation();
103 // rest return an empty bean
104 assertNotNull( organisationInformation );
105 organisationInformation = new OrganisationInformation();
106 organisationInformation.setLogoLocation( "http://foo.com'/><svg/onload=alert(/logoLocation_xss/)>" );
107 organisationInformation.setName( "foo org" );
108 organisationInformation.setUrl( "http://foo.com" );
111 getArchivaAdministrationService().setOrganisationInformation(organisationInformation);
112 fail("RepositoryAdminException expected. Bad URL content should not be allowed for logo location.");
113 } catch (BadRequestException e) {
120 public void badOrganizationUrl()
123 OrganisationInformation organisationInformation =
124 getArchivaAdministrationService().getOrganisationInformation();
126 // rest return an empty bean
127 assertNotNull( organisationInformation );
129 organisationInformation = new OrganisationInformation();
130 organisationInformation.setLogoLocation( "http://foo.com/logo.jpg" );
131 organisationInformation.setName( "foo org" );
132 organisationInformation.setUrl( "http://foo.com'/><svg/onload=alert(/url_xss/)>" );
135 getArchivaAdministrationService().setOrganisationInformation(organisationInformation);
136 fail("RepositoryAdminException expected. Bad URL content should not be allowed for logo location.");
137 } catch (BadRequestException e) {
144 public void uiConfigurationReadUpdate()
147 UiConfiguration ui = getArchivaAdministrationService().getUiConfiguration();
149 // assert default values
150 assertFalse( ui.isDisableEasterEggs() );
151 assertFalse( ui.isDisableRegistration() );
152 assertTrue( ui.isAppletFindEnabled() );
153 assertTrue( ui.isShowFindArtifacts() );
154 assertNull( ui.getApplicationUrl() );
156 ui.setAppletFindEnabled( false );
157 ui.setShowFindArtifacts( false );
158 ui.setDisableEasterEggs( true );
159 ui.setDisableRegistration( true );
160 String url = "http://foo.fr/bar";
161 ui.setApplicationUrl( url );
163 getArchivaAdministrationService().setUiConfiguration( ui );
165 ui = getArchivaAdministrationService().getUiConfiguration();
167 assertTrue( ui.isDisableEasterEggs() );
168 assertTrue( ui.isDisableRegistration() );
169 assertFalse( ui.isAppletFindEnabled() );
170 assertFalse( ui.isShowFindArtifacts() );
171 assertEquals( url, ui.getApplicationUrl() );
175 public void uiConfigurationUpdate_ApplicationUrlHasTrailingSlash()
178 UiConfiguration ui = getArchivaAdministrationService().getUiConfiguration();
180 // assertNull( ui.getApplicationUrl() );
182 String url = "http://foo.fr/bar/";
183 ui.setApplicationUrl( url );
185 getArchivaAdministrationService().setUiConfiguration( ui );
187 ui = getArchivaAdministrationService().getUiConfiguration();
189 assertEquals( "http://foo.fr/bar", ui.getApplicationUrl() );
191 // test if multiple '/' is trailing
192 url = "http://foo.fr/bar//";
194 ui.setApplicationUrl(url);
196 getArchivaAdministrationService().setUiConfiguration(ui);
198 ui = getArchivaAdministrationService().getUiConfiguration();
200 assertEquals( "http://foo.fr/bar", ui.getApplicationUrl() );
204 public void getKnownContentAdminRepositoryConsumer()
207 List<AdminRepositoryConsumer> consumers =
208 getArchivaAdministrationService().getKnownContentAdminRepositoryConsumers();
209 assertFalse( consumers.isEmpty() );
213 public void getInvalidContentAdminRepositoryConsumer()
216 List<AdminRepositoryConsumer> consumers =
217 getArchivaAdministrationService().getInvalidContentAdminRepositoryConsumers();
218 assertFalse( consumers.isEmpty() );
219 assertAllDisabled( consumers );
221 getArchivaAdministrationService().enabledInvalidContentConsumer( "foo" );
223 consumers = getArchivaAdministrationService().getInvalidContentAdminRepositoryConsumers();
224 assertFalse( consumers.isEmpty() );
225 assertAllEnabled( consumers );
227 getArchivaAdministrationService().disabledInvalidContentConsumer( "foo" );
229 consumers = getArchivaAdministrationService().getInvalidContentAdminRepositoryConsumers();
231 assertAllDisabled( consumers );
233 assertFalse( consumers.isEmpty() );
236 private void assertAllEnabled( List<AdminRepositoryConsumer> consumers )
238 for ( AdminRepositoryConsumer consumer : consumers )
240 assertTrue( consumer.isEnabled() );
244 private void assertAllDisabled( List<AdminRepositoryConsumer> consumers )
246 for ( AdminRepositoryConsumer consumer : consumers )
248 assertFalse( consumer.isEnabled() );