Skip to content

Commit 6afd2a4

Browse files
committed
unit test showing SecretBytes are not usable via remoting
demonstrates #1013
1 parent 07bcd52 commit 6afd2a4

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/test/java/com/cloudbees/plugins/credentials/SecretBytesTest.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,17 @@
2323
*/
2424
package com.cloudbees.plugins.credentials;
2525

26+
import hudson.slaves.DumbSlave;
2627
import java.nio.charset.StandardCharsets;
2728
import java.util.Random;
2829
import jenkins.model.Jenkins;
30+
import jenkins.security.MasterToSlaveCallable;
2931
import org.apache.commons.codec.binary.Base64;
3032
import org.apache.commons.lang3.RandomStringUtils;
3133
import org.junit.jupiter.api.Test;
3234
import org.jvnet.hudson.test.Issue;
35+
import org.jvnet.hudson.test.JenkinsRule;
36+
import org.jvnet.hudson.test.junit.jupiter.WithJenkins;
3337

3438
import static org.hamcrest.MatcherAssert.assertThat;
3539
import static org.hamcrest.Matchers.containsString;
@@ -163,4 +167,29 @@ void largeRawString__chunking__urlSafe() {
163167
}
164168

165169

170+
@WithJenkins
171+
@Test
172+
public void serialisationOverRemoting(JenkinsRule r) throws Exception {
173+
final byte[] data = new byte[] {0x01,0x02,0x03,0x04,0x05};
174+
final SecretBytes localSecretBytes = SecretBytes.fromRawBytes(data);
175+
DumbSlave onlineSlave = r.createOnlineSlave();
176+
onlineSlave.getChannel().call(new CheckSecretBytesCallable(localSecretBytes,data));
177+
}
178+
179+
private static class CheckSecretBytesCallable extends MasterToSlaveCallable<Void, AssertionError> {
180+
181+
private SecretBytes sb;
182+
private byte[] expectedUnencryptedValue;
183+
184+
CheckSecretBytesCallable(SecretBytes sb, byte[] expectedUnencryptedValue) {
185+
this.sb = sb;
186+
this.expectedUnencryptedValue = expectedUnencryptedValue;
187+
}
188+
189+
@Override
190+
public Void call() throws AssertionError {
191+
assertThat(sb.getPlainData(), is(expectedUnencryptedValue));
192+
return null;
193+
}
194+
}
166195
}

0 commit comments

Comments
 (0)