Skip to content

Commit 4686890

Browse files
authored
Merge pull request #68 from oracle/Issue#66-validate-exploded-libraries
Allow directories in path
2 parents 29b1e96 + b9aee7e commit 4686890

File tree

11 files changed

+215
-2
lines changed

11 files changed

+215
-2
lines changed

core/src/main/java/oracle/weblogic/deploy/util/WLSDeployArchive.java

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,55 @@ public boolean containsFile(String path) throws WLSDeployArchiveIOException {
277277
return result;
278278
}
279279

280+
/**
281+
* Determines whether or not the provided path is a directory in the archive file.
282+
*
283+
* @param path the path into the archive file to test
284+
* @return true if the specified location was found in the archive file and is a directory
285+
* @throws WLSDeployArchiveIOException if an error occurs reading the archive file
286+
* @throws IllegalArgumentException if the path is null or empty
287+
*/
288+
public boolean containsPath(String path) throws WLSDeployArchiveIOException {
289+
final String METHOD = "isAPath";
290+
291+
LOGGER.entering(CLASS, METHOD, path);
292+
validateNonEmptyString(path, "path", METHOD);
293+
294+
boolean result = false;
295+
// Verify that the path is into the binary root directory so that we do not allow random content.
296+
if (isPathIntoArchive(path)) {
297+
List<String> entries = getZipFile().listZipEntries();
298+
result = !entries.contains(path) && zipListContainsPath(entries, path);
299+
}
300+
LOGGER.exiting(CLASS, METHOD, result);
301+
return result;
302+
}
303+
304+
/**
305+
* Determines whether or not the provided path is a directory or a file in a directory
306+
* in the archive file.
307+
*
308+
* @param path the path into the archive file to test
309+
* @return true if the specified location was found in the archive file
310+
* @throws WLSDeployArchiveIOException if an error occurs reading the archive file
311+
* @throws IllegalArgumentException if the path is null or empty
312+
*/
313+
public boolean containsFileOrPath(String path) throws WLSDeployArchiveIOException {
314+
final String METHOD = "containsFileOrPath";
315+
316+
LOGGER.entering(CLASS, METHOD, path);
317+
validateNonEmptyString(path, "path", METHOD);
318+
319+
boolean result = false;
320+
// Verify that the path is into the binary root directory so that we do not allow random content.
321+
if (isPathIntoArchive(path)) {
322+
List<String> entries = getZipFile().listZipEntries();
323+
result = entries.contains(path) || zipListContainsPath(entries, path);
324+
}
325+
LOGGER.exiting(CLASS, METHOD, result);
326+
return result;
327+
}
328+
280329
/**
281330
* Extract the specified file to the specified location (which is typically the domain home). For example,
282331
* if the path is wlsdeploy/applications/myapp.ear and the extractToLocation is the domain home, the file
@@ -1091,6 +1140,19 @@ protected void extractFileFromZip(String itemToExtract, String fromDir, String t
10911140
// Private Helper methods used by the protected methods above... //
10921141
///////////////////////////////////////////////////////////////////////////
10931142

1143+
private static boolean zipListContainsPath(List<String> entries, String path) {
1144+
boolean foundInList = false;
1145+
if (path != null && entries != null) {
1146+
for (String entry : entries) {
1147+
if (entry.startsWith(path)) {
1148+
foundInList = true;
1149+
break;
1150+
}
1151+
}
1152+
}
1153+
return foundInList;
1154+
}
1155+
10941156
private static void copyFile(InputStream input, FileOutputStream output) throws IOException {
10951157
byte[] readBuffer = new byte[READ_BUFFER_SIZE];
10961158

core/src/main/python/wlsdeploy/tool/util/archive_helper.py

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def contains_file(self, path):
7979
"""
8080
Does the archive file contain the specified location?
8181
:param path: the path to test
82-
:return: True, if the path was found in the archive file, False otherwise
82+
:return: True, if the path was found in the archive file and is a file, False otherwise
8383
:raises: BundleAwareException of the appropriate type: if an error occurs
8484
"""
8585
_method_name = 'contains_file'
@@ -95,6 +95,46 @@ def contains_file(self, path):
9595
self.__logger.exiting(class_name=self.__class_name, method_name=_method_name, result=result)
9696
return result
9797

98+
def contains_path(self, path):
99+
"""
100+
Check that the provided path is a path, not a file, contained inside the archive file
101+
:param path: the path to test
102+
:return: True, if the path was found in the archive file and is a path, False otherwise
103+
:raises: BundleAwareException of the appropriate type: if an error occurs
104+
"""
105+
_method_name = 'contains_path'
106+
107+
self.__logger.entering(path, class_name=self.__class_name, method_name=_method_name)
108+
try:
109+
result = self.__archive_file.containsPath(path)
110+
except (IllegalArgumentException, WLSDeployArchiveIOException), e:
111+
ex = exception_helper.create_exception(self.__exception_type, "WLSDPLY-19308", path,
112+
self.__archive_file_name, e.getLocalizedMessage(), error=e)
113+
self.__logger.throwing(ex, class_name=self.__class_name, method_name=_method_name)
114+
raise ex
115+
self.__logger.exiting(class_name=self.__class_name, method_name=_method_name, result=result)
116+
return result
117+
118+
def contains_file_or_path(self, path):
119+
"""
120+
Check that the provided path is a file or path contained inside the archive file
121+
:param path: the path to test
122+
:return: True, if the path was found in the archive file. False otherwise
123+
:raises: BundleAwareException of the appropriate type: if an error occurs
124+
"""
125+
_method_name = 'contains_file_or_path'
126+
127+
self.__logger.entering(path, class_name=self.__class_name, method_name=_method_name)
128+
try:
129+
result = self.__archive_file.containsFileOrPath(path)
130+
except (IllegalArgumentException, WLSDeployArchiveIOException), e:
131+
ex = exception_helper.create_exception(self.__exception_type, "WLSDPLY-19309", path,
132+
self.__archive_file_name, e.getLocalizedMessage(), error=e)
133+
self.__logger.throwing(ex, class_name=self.__class_name, method_name=_method_name)
134+
raise ex
135+
self.__logger.exiting(class_name=self.__class_name, method_name=_method_name, result=result)
136+
return result
137+
98138
def extract_file(self, path, location=None):
99139
"""
100140
Extract the specified file from the archive into the Domain Home directory.

core/src/main/python/wlsdeploy/tool/validate/validator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -881,7 +881,7 @@ def __validate_single_path_in_archive(self, path, attribute_name, model_folder_p
881881
#
882882
if WLSDeployArchive.isPathIntoArchive(path):
883883
if self._archive_helper is not None:
884-
archive_has_file = self._archive_helper.contains_file(path)
884+
archive_has_file = self._archive_helper.contains_file_or_path(path)
885885
if not archive_has_file:
886886
validation_result.add_error('WLSDPLY-05024', attribute_name, model_folder_path,
887887
path, self._archive_file_name)

core/src/test/java/oracle/weblogic/deploy/util/WLSDeployArchiveTest.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ public class WLSDeployArchiveTest {
2929
private static final String APP2_ENTRY_NAME1 = "wlsdeploy/applications/my-other-app.war";
3030
private static final String APP2_ENTRY_NAME2 = "wlsdeploy/applications/my-other-app(1).war";
3131
private static final String APP2_ENTRY_NAME3 = "wlsdeploy/applications/my-other-app(2).war";
32+
private static final String INVALID_APP_ENTRY_NAME = "wlsdeploy/applications/does-not-exist.war";
33+
private static final String APP_DIR_TO_ADD = "src/test/resources/my-app/";
34+
private static final String APP_DIR_ENTRY_NAME = "wlsdeploy/applications/my-app/";
35+
private static final String INVALID_DIR_ENTRY_NAME = "wlsdeploy/applications/does-not-exist/";
3236

3337
private static final String ZIP_FILE_EXISTING_EMPTY_FILE = "my-empty-zip.zip";
3438
private static final String ZIP_FILE_EXISTING_BINARIES_FILE = "DiscoveredDemoDomain.zip";
@@ -88,6 +92,37 @@ public void testAddRemoveModelWithEmptyZip() throws Exception {
8892
archive.close();
8993
}
9094

95+
@Test
96+
public void testAddDirectory() throws Exception {
97+
WLSDeployArchive archive = new WLSDeployArchive(APPS_ARCHIVE_FILE_NAME);
98+
String appName = archive.addApplication(new File(APP_DIR_TO_ADD));
99+
Assert.assertEquals("unexpected app name: " + appName, APP_DIR_ENTRY_NAME, appName);
100+
archive.close();
101+
}
102+
103+
@Test
104+
public void testIsAFile() throws Exception {
105+
WLSDeployArchive archive = new WLSDeployArchive(APPS_ARCHIVE_FILE_NAME);
106+
archive.addApplication(new File(APP1_TO_ADD));
107+
Assert.assertTrue("File not found in archive: " + APP1_ENTRY_NAME1, archive.containsFile(APP1_ENTRY_NAME1));
108+
Assert.assertTrue("File not found in archive: "
109+
+ APP1_ENTRY_NAME1, archive.containsFileOrPath(APP1_ENTRY_NAME1));
110+
Assert.assertFalse("Is not a File", archive.containsFile(APP_DIR_ENTRY_NAME));
111+
Assert.assertFalse("File should not exist", archive.containsFileOrPath(INVALID_APP_ENTRY_NAME));
112+
archive.close();
113+
}
114+
115+
@Test
116+
public void testIsAPath() throws Exception {
117+
WLSDeployArchive archive = new WLSDeployArchive(APPS_ARCHIVE_FILE_NAME);
118+
archive.addApplication(new File(APP_DIR_TO_ADD));
119+
Assert.assertTrue("Path not found in archive: " + APP_DIR_ENTRY_NAME, archive.containsPath(APP_DIR_ENTRY_NAME));
120+
Assert.assertTrue("Path not found in archive: " + APP_DIR_ENTRY_NAME,
121+
archive.containsFileOrPath(APP_DIR_ENTRY_NAME));
122+
Assert.assertFalse("Is not a Path", archive.containsPath(APP1_ENTRY_NAME1));
123+
Assert.assertFalse("Path should not exist", archive.containsFileOrPath(INVALID_DIR_ENTRY_NAME));
124+
}
125+
91126
@Test
92127
public void testClearAllBinariesWithEmptyZip() throws Exception {
93128
WLSDeployZipFileTest.copyFile(ZIP_FILE_EXISTING_BINARIES_FILE);
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Manifest-Version: 1.0
2+
Archiver-Version: Plexus Archiver
3+
Built-By: RPATRICK
4+
Created-By: Apache Maven 3.3.3
5+
Build-Jdk: 1.8.0_60
6+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#Generated by Apache Maven
2+
#Thu Nov 19 18:16:35 CST 2015
3+
version=0.2-SNAPSHOT
4+
groupId=oracle.jcs.lifecycle
5+
artifactId=get-listen-address-app
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<artifactId>get-listen-address-app</artifactId>
5+
<packaging>war</packaging>
6+
7+
<parent>
8+
<groupId>oracle.jcs.lifecycle</groupId>
9+
<artifactId>las-system-test-apps</artifactId>
10+
<version>0.2-SNAPSHOT</version>
11+
<relativePath>../pom.xml</relativePath>
12+
</parent>
13+
14+
<dependencies>
15+
<dependency>
16+
<groupId>javaee</groupId>
17+
<artifactId>javaee-api</artifactId>
18+
<version>5</version>
19+
<scope>provided</scope>
20+
</dependency>
21+
</dependencies>
22+
23+
<build>
24+
<plugins>
25+
<plugin>
26+
<groupId>org.apache.maven.plugins</groupId>
27+
<artifactId>maven-war-plugin</artifactId>
28+
<configuration>
29+
<webXml>${basedir}/src/main/webapp/WEB-INF/web.xml</webXml>
30+
</configuration>
31+
</plugin>
32+
</plugins>
33+
</build>
34+
</project>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<web-app
3+
xmlns="http://java.sun.com/xml/ns/j2ee"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
version="2.5">
6+
<servlet>
7+
<servlet-name>Get Listen Address Servlet</servlet-name>
8+
<servlet-class>com.oracle.platform.GetListenAddressServlet</servlet-class>
9+
<run-as>
10+
<role-name>server-admin</role-name>
11+
</run-as>
12+
</servlet>
13+
<servlet-mapping>
14+
<servlet-name>Get Listen Address Servlet</servlet-name>
15+
<url-pattern>/listen</url-pattern>
16+
</servlet-mapping>
17+
<welcome-file-list>
18+
<welcome-file>/listen</welcome-file>
19+
</welcome-file-list>
20+
<security-role>
21+
<role-name>server-admin</role-name>
22+
</security-role>
23+
</web-app>

0 commit comments

Comments
 (0)