Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>6.2189.v695a_c41f5249</version>
<version>6.2211.v27f680c93c53</version>
<relativePath/>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@

import edu.umd.cs.findbugs.annotations.CheckForNull;
import edu.umd.cs.findbugs.annotations.NonNull;
import java.io.OutputStream;
import jenkins.model.Jenkins;
import net.sf.json.JSON;
import org.jenkinsci.plugins.scriptsecurity.sandbox.Whitelist;
Expand Down Expand Up @@ -256,10 +257,7 @@ String hashClasspathEntry(URL entry) throws IOException {
try {
MessageDigest digest = digest();
try (InputStream is = entry.openStream(); BufferedInputStream bis = new BufferedInputStream(is); DigestInputStream input = new DigestInputStream(bis, digest)) {
byte[] buffer = new byte[1024];
while (input.read(buffer) != -1) {
// discard
}
input.transferTo(OutputStream.nullOutputStream());
return prefix() + Util.toHexString(digest.digest());
}
} catch (NoSuchAlgorithmException x) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import static org.hamcrest.Matchers.containsInRelativeOrder;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
Expand Down Expand Up @@ -145,6 +146,13 @@ public void testClasspathEntriesConvertedOnUse() throws Throwable {
});
}

@Test
public void hashClasspathEntry() throws Exception {
var url = HasherScriptApprovalTest.class.getResource("/org/jenkinsci/plugins/scriptsecurity/sandbox/groovy/somejar.jar");
assertThat(ScriptApproval.Hasher.SHA512.hashClasspathEntry(url), is("SHA512:8c649f770baefbbf33a2ed6bb06a4ab5cd8b1921fec4176906e068337d76aa54b28aeac6987a46d5e6c73fcbbfaab93651a4fb082bcc96f1511e6395eb3b2b5f"));
assertThat(ScriptApproval.Hasher.SHA1.hashClasspathEntry(url), is("049d9ec67a2a95263ee50e7db8e406b97d300bbe"));
}

private void addApprovedClasspathEntries(final ScriptApproval approval) throws IOException {
URL url = getJar("org/apache/commons/lang3/StringUtils.class");
ScriptApproval.ApprovedClasspathEntry acp = new ScriptApproval.ApprovedClasspathEntry(
Expand Down
Loading