File D:\maven-qcr-plugin-testsunitaires\qcr4java\jenkins-master\target\site\qc\core\src\test\java\hudson\util\MockSecretRule.java.html

1 package hudson.util;
2
3 import hudson.Util;
4 import org.junit.rules.ExternalResource;
5
6 import java.security.SecureRandom;
7
8 /**
9 * JUnit rule that cleans that sets a temporary {@link Secret#SECRET} value.
10 *
11 * @author Kohsuke Kawaguchi
12 */
13 public class MockSecretRule extends ExternalResource {
14
15 private String value;
16
17 @Override
18 protected void before() throws Throwable {
19 byte[] random = new byte[32];
20 sr.nextBytes(random);
21 value = Util.toHexString(random);
22 Secret.SECRET = value;
23 }
24
25 @Override
26 protected void after() {
27 if (!Secret.SECRET.equals(value))
28 throw new IllegalStateException("Someone tinkered with Secret.SECRET");
29 Secret.SECRET = null;
30 }
31
32 private static final SecureRandom sr = new SecureRandom();
33 }
34