Skip to content

Commit

Permalink
Fixed missing apple.security to SecurityTest. Issue: #67
Browse files Browse the repository at this point in the history
Also fixes a problem related to running JUnit Tests from IntelliJ on Mac
systems. IntelliJ resides in a folder `IntelliJ App` (mind the space)  which executes the
JUnit tests and adds therefore its own Jars to the classpath. When
converted from an URL into an URI we recieve an illegal character
exception. The fix was to UrlEscape the path variable within the `newUrl` method.

Signed-off-by: Dennis Rippinger <dennis.rippinger@gmail.com>
  • Loading branch information
DennisRippinger committed May 11, 2018
1 parent c659570 commit dcaadbf
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void only_security_infrastructure_should_use_java_security() {
@Test
public void only_security_infrastructure_should_use_java_security_on_whole_classpath() {
ArchRule rule = classes().that().resideInAPackage("java.security.cert..")
.should().onlyBeAccessed().byAnyPackage("..example.security..", "java..", "..sun..", "javax..");
.should().onlyBeAccessed().byAnyPackage("..example.security..", "java..", "..sun..", "javax..", "apple.security..");

JavaClasses classes = new ClassFileImporter().importClasspath(onlyAppAndRuntime());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void only_security_infrastructure_should_use_java_security() {
@Override
public void only_security_infrastructure_should_use_java_security_on_whole_classpath() {
expectViolationFromWrongSecurityCheck("classes that reside in a package 'java.security.cert..' "
+ "should only be accessed by any package ['..example.security..', 'java..', '..sun..', 'javax..']");
+ "should only be accessed by any package ['..example.security..', 'java..', '..sun..', 'javax..', 'apple.security..']");

super.only_security_infrastructure_should_use_java_security_on_whole_classpath();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.google.common.base.Splitter;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableList;
import com.google.common.net.UrlEscapers;
import com.tngtech.archunit.Internal;
import com.tngtech.archunit.base.ArchUnitException.LocationException;
import com.tngtech.archunit.base.Optional;
Expand Down Expand Up @@ -96,10 +97,13 @@ private static Optional<URL> newJarUri(String path) {

private static Optional<URL> newUrl(String protocol, String path) {
try {
return Optional.of(new URL(protocol + "://" + path));
return Optional.of(new URL(protocol + "://" + UrlEscapers.urlFragmentEscaper().escape(path)));
} catch (MalformedURLException e) {
LOG.warn("Cannot parse URL from path " + path, e);
return Optional.absent();
} catch (IllegalArgumentException e){
LOG.warn("Cannot escape fragments from path" + path, e);
return Optional.absent();
}
}

Expand Down

0 comments on commit dcaadbf

Please sign in to comment.