|
23 | 23 | */ |
24 | 24 | package com.cloudbees.plugins.credentials; |
25 | 25 |
|
| 26 | +import hudson.slaves.DumbSlave; |
26 | 27 | import java.nio.charset.StandardCharsets; |
27 | 28 | import java.util.Random; |
28 | 29 | import jenkins.model.Jenkins; |
| 30 | +import jenkins.security.MasterToSlaveCallable; |
29 | 31 | import org.apache.commons.codec.binary.Base64; |
30 | 32 | import org.apache.commons.lang3.RandomStringUtils; |
31 | 33 | import org.junit.jupiter.api.Test; |
32 | 34 | import org.jvnet.hudson.test.Issue; |
| 35 | +import org.jvnet.hudson.test.JenkinsRule; |
| 36 | +import org.jvnet.hudson.test.junit.jupiter.WithJenkins; |
33 | 37 |
|
34 | 38 | import static org.hamcrest.MatcherAssert.assertThat; |
35 | 39 | import static org.hamcrest.Matchers.containsString; |
@@ -163,4 +167,29 @@ void largeRawString__chunking__urlSafe() { |
163 | 167 | } |
164 | 168 |
|
165 | 169 |
|
| 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 | + } |
166 | 195 | } |
0 commit comments