Skip to content

Commit 8b38053

Browse files
authored
Remove hard-coded ADR bug number (#202)
* replace hard-coded ADR bug number with dynamic search for omitting ADR patches * improve performance by eliminating duplicate calls to ARU for PSU and recommended patches * set PSU version for patches when applying latestPSU/recommendedPatches at the same time as new patches * restructured ARU classes into their own package * created ARU patch type to parse ARU patch responses * secure usage of XML parser to prevent XXE * replaced EasyMock unit tests
1 parent ae1d149 commit 8b38053

35 files changed

+1901
-1065
lines changed

imagetool/pom.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,6 @@
5757
<artifactId>annotations</artifactId>
5858
<scope>provided</scope>
5959
</dependency>
60-
<dependency>
61-
<groupId>org.easymock</groupId>
62-
<artifactId>easymock</artifactId>
63-
<scope>test</scope>
64-
</dependency>
6560
</dependencies>
6661

6762
<build>

imagetool/src/main/java/com/oracle/weblogic/imagetool/api/model/CachedFile.java

Lines changed: 3 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,12 @@
1010
import java.nio.file.Path;
1111
import java.nio.file.Paths;
1212
import java.util.Objects;
13-
import javax.xml.xpath.XPathExpressionException;
1413

1514
import com.oracle.weblogic.imagetool.cachestore.CacheStore;
1615
import com.oracle.weblogic.imagetool.installer.InstallerType;
1716
import com.oracle.weblogic.imagetool.logging.LoggingFacade;
1817
import com.oracle.weblogic.imagetool.logging.LoggingFactory;
19-
import com.oracle.weblogic.imagetool.util.HttpUtil;
2018
import com.oracle.weblogic.imagetool.util.Utils;
21-
import org.apache.http.client.fluent.Executor;
22-
import org.apache.http.client.fluent.Request;
2319

2420
/**
2521
* Base class to represent either an installer or a patch file.
@@ -69,14 +65,10 @@ public String getKey() {
6965
if (id.contains(CacheStore.CACHE_KEY_SEPARATOR)) {
7066
return id;
7167
} else {
72-
return buildKeyFromVersion(getVersion());
68+
return id + CacheStore.CACHE_KEY_SEPARATOR + getVersion();
7369
}
7470
}
7571

76-
protected String buildKeyFromVersion(String version) {
77-
return id + CacheStore.CACHE_KEY_SEPARATOR + version;
78-
}
79-
8072
/**
8173
* Get the version number for this cache entry/file.
8274
* @return the string version of this cached file.
@@ -91,7 +83,7 @@ public String getVersion() {
9183
* @return the Path of the file, if found
9284
* @throws IOException throws FileNotFoundException, if this cached file (key) could not be located in the cache
9385
*/
94-
public String resolve(CacheStore cacheStore) throws IOException, XPathExpressionException {
86+
public String resolve(CacheStore cacheStore) throws IOException {
9587
// check entry exists in cache
9688
String key = getKey();
9789
logger.entering(key);
@@ -110,7 +102,7 @@ public String resolve(CacheStore cacheStore) throws IOException, XPathExpression
110102
* @param buildContextDir directory to copy file to
111103
* @return the path of the file copied to the Docker build context directory
112104
*/
113-
public Path copyFile(CacheStore cacheStore, String buildContextDir) throws IOException, XPathExpressionException {
105+
public Path copyFile(CacheStore cacheStore, String buildContextDir) throws IOException {
114106
logger.entering();
115107
Path result;
116108
String sourceFile = resolve(cacheStore);
@@ -127,31 +119,4 @@ public Path copyFile(CacheStore cacheStore, String buildContextDir) throws IOExc
127119
logger.exiting(result);
128120
return result;
129121
}
130-
131-
132-
/**
133-
* Download a file from the url.
134-
*
135-
* @param url url of the aru server
136-
* @param fileName full path to save the file
137-
* @param username userid for support account
138-
* @param password password for support account
139-
* @throws IOException when it fails to access the url
140-
*/
141-
142-
public void downloadFile(String url, String fileName, String username, String password)
143-
throws IOException {
144-
logger.entering(url);
145-
try {
146-
Executor.newInstance(HttpUtil.getOraClient(username, password))
147-
.execute(Request.Get(url).connectTimeout(30000).socketTimeout(30000))
148-
.saveContent(new File(fileName));
149-
} catch (Exception ex) {
150-
String message = String.format("Failed to download and save file %s from %s: %s", fileName, url,
151-
ex.getLocalizedMessage());
152-
logger.severe(message);
153-
throw new IOException(message, ex);
154-
}
155-
logger.exiting(fileName);
156-
}
157122
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (c) 2020, Oracle Corporation and/or its affiliates.
2+
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
3+
4+
package com.oracle.weblogic.imagetool.aru;
5+
6+
public class AruException extends Exception {
7+
public AruException() {
8+
super();
9+
}
10+
11+
public AruException(String message) {
12+
super(message);
13+
}
14+
15+
public AruException(String message, Throwable thrown) {
16+
super(message, thrown);
17+
}
18+
}

imagetool/src/main/java/com/oracle/weblogic/imagetool/util/AruHttpHelper.java renamed to imagetool/src/main/java/com/oracle/weblogic/imagetool/aru/AruHttpHelper.java

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
// Copyright (c) 2019, 2020, Oracle Corporation and/or its affiliates.
22
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
33

4-
package com.oracle.weblogic.imagetool.util;
4+
package com.oracle.weblogic.imagetool.aru;
55

66
import java.io.IOException;
7-
import javax.xml.XMLConstants;
8-
import javax.xml.parsers.DocumentBuilder;
9-
import javax.xml.parsers.DocumentBuilderFactory;
107
import javax.xml.parsers.ParserConfigurationException;
118
import javax.xml.xpath.XPathExpressionException;
129

13-
import com.oracle.weblogic.imagetool.installer.AruProduct;
10+
import com.oracle.weblogic.imagetool.util.HttpUtil;
11+
import com.oracle.weblogic.imagetool.util.XPathUtil;
1412
import org.w3c.dom.Document;
1513
import org.w3c.dom.Element;
1614
import org.w3c.dom.Node;
@@ -171,7 +169,7 @@ AruHttpHelper execValidation(String url, String payload) throws IOException {
171169
AruHttpHelper validation() throws IOException {
172170
NodeList conflictSets;
173171
try {
174-
conflictSets = XPathUtil.applyXPathReturnNodeList(results(),
172+
conflictSets = XPathUtil.nodelist(results(),
175173
"/conflict_check/conflict_sets/set");
176174
} catch (XPathExpressionException xee) {
177175
throw new IOException(xee);
@@ -181,7 +179,7 @@ AruHttpHelper validation() throws IOException {
181179
success = false;
182180
String expression = "/conflict_check/conflict_sets/set/merge_patches";
183181

184-
NodeList nodeList = XPathUtil.applyXPathReturnNodeList(results(), expression);
182+
NodeList nodeList = XPathUtil.nodelist(results(), expression);
185183

186184
createResultDocument(nodeList);
187185

@@ -203,15 +201,7 @@ AruHttpHelper validation() throws IOException {
203201
*/
204202
AruHttpHelper createResultDocument(NodeList nodeList) throws IOException {
205203
try {
206-
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
207-
208-
// Prevent XXE attacks
209-
dbf.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
210-
dbf.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
211-
dbf.setAttribute(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "");
212-
213-
DocumentBuilder builder = dbf.newDocumentBuilder();
214-
Document doc = builder.newDocument();
204+
Document doc = HttpUtil.documentBuilder().newDocument();
215205
Element element = doc.createElement("results");
216206

217207
for (int i = 0; i < nodeList.getLength(); i++) {
@@ -242,11 +232,11 @@ private String parsePatchValidationError() {
242232
Node conflictsResultNode = results();
243233
if (conflictsResultNode != null) {
244234
try {
245-
NodeList patchSets = XPathUtil.applyXPathReturnNodeList(conflictsResultNode, "//merge_patches");
235+
NodeList patchSets = XPathUtil.nodelist(conflictsResultNode, "//merge_patches");
246236
stringBuilder.append("patch conflicts detected: ");
247237
for (int i = 0; i < patchSets.getLength(); i++) {
248238
stringBuilder.append("[");
249-
NodeList bugNumbers = XPathUtil.applyXPathReturnNodeList(patchSets.item(i), "patch/bug/number"
239+
NodeList bugNumbers = XPathUtil.nodelist(patchSets.item(i), "patch/bug/number"
250240
+ "/text()");
251241
for (int j = 0; j < bugNumbers.getLength(); j++) {
252242
stringBuilder.append(bugNumbers.item(j).getNodeValue());
@@ -267,10 +257,10 @@ private String parsePatchValidationError() {
267257
private void searchResult(Document result) throws IOException {
268258
success = true;
269259
try {
270-
NodeList nodeList = XPathUtil.applyXPathReturnNodeList(result, "/results/error");
260+
NodeList nodeList = XPathUtil.nodelist(result, "/results/error");
271261
if (nodeList.getLength() > 0) {
272262
success = false;
273-
errorMessage = XPathUtil.applyXPathReturnString(result, "/results/error/message");
263+
errorMessage = XPathUtil.string(result, "/results/error/message");
274264
} else {
275265
results = result;
276266
}

0 commit comments

Comments
 (0)