6
6
import com .cloudbees .plugins .credentials .Credentials ;
7
7
import com .cloudbees .plugins .credentials .CredentialsMatchers ;
8
8
import com .cloudbees .plugins .credentials .CredentialsScope ;
9
+ import com .cloudbees .plugins .credentials .SecretBytes ;
9
10
import com .cloudbees .plugins .credentials .impl .CertificateCredentialsImpl ;
10
11
import com .cloudbees .plugins .credentials .impl .UsernamePasswordCredentialsImpl ;
11
- import edu .umd .cs .findbugs .annotations .NonNull ;
12
+ import java .io .ByteArrayOutputStream ;
13
+ import java .security .KeyStore ;
12
14
import java .util .Collections ;
13
15
import java .util .List ;
16
+ import java .util .UUID ;
14
17
import jenkins .authentication .tokens .api .AuthenticationTokenContext ;
15
18
import jenkins .authentication .tokens .api .AuthenticationTokens ;
16
19
import org .junit .ClassRule ;
@@ -57,7 +60,7 @@ public void authenticationContextTest() {
57
60
}
58
61
59
62
@ Test
60
- public void passwordCredentialsTest () {
63
+ public void passwordCredentialsTest () throws Exception {
61
64
List <Credentials > list = Collections .<Credentials >singletonList (new UsernamePasswordCredentialsImpl (
62
65
CredentialsScope .SYSTEM , "dummy" , "dummy" , "user" , "pass" ));
63
66
AuthenticationTokenContext ctx = BitbucketAuthenticator .authenticationContext ((null ));
@@ -69,9 +72,11 @@ public void passwordCredentialsTest() {
69
72
}
70
73
71
74
@ Test
72
- public void certCredentialsTest () {
75
+ public void certCredentialsTest () throws Exception {
76
+ // random password in test code to keep code-ql happy 🤮
77
+ String password = UUID .randomUUID ().toString ();
73
78
List <Credentials > list = Collections .<Credentials >singletonList (new CertificateCredentialsImpl (
74
- CredentialsScope .SYSTEM , "dummy" , "dummy" , " password" , new DummyKeyStoreSource ()));
79
+ CredentialsScope .SYSTEM , "dummy" , "dummy" , password , new DummyKeyStoreSource (password )));
75
80
76
81
AuthenticationTokenContext ctx = BitbucketAuthenticator .authenticationContext (null );
77
82
Credentials c = CredentialsMatchers .firstOrNull (list , AuthenticationTokens .matcher (ctx ));
@@ -87,15 +92,20 @@ public void certCredentialsTest() {
87
92
assertThat (AuthenticationTokens .convert (ctx , c ), notNullValue ());
88
93
}
89
94
90
- private static class DummyKeyStoreSource extends CertificateCredentialsImpl .KeyStoreSource {
91
- @ NonNull
92
- @ Override
93
- public byte [] getKeyStoreBytes () { return new byte [0 ]; }
95
+ private static class DummyKeyStoreSource extends CertificateCredentialsImpl .UploadedKeyStoreSource {
94
96
95
- @ Override
96
- public long getKeyStoreLastModified () { return 0 ; }
97
+ DummyKeyStoreSource (String password ) throws Exception {
98
+ super (null , dummyPKCS12Store (password ));
99
+ }
100
+
101
+ private static SecretBytes dummyPKCS12Store (String password ) throws Exception {
102
+ KeyStore ks = KeyStore .getInstance ("PKCS12" );
103
+ ks .load (null , password .toCharArray ());
104
+ ByteArrayOutputStream bos = new ByteArrayOutputStream ();
105
+ ks .store (bos , password .toCharArray ());
106
+ return SecretBytes .fromBytes (bos .toByteArray ());
107
+ }
97
108
98
- @ Override
99
- public boolean isSnapshotSource () { return true ; }
100
109
}
110
+
101
111
}
0 commit comments