66import com .cloudbees .plugins .credentials .Credentials ;
77import com .cloudbees .plugins .credentials .CredentialsMatchers ;
88import com .cloudbees .plugins .credentials .CredentialsScope ;
9+ import com .cloudbees .plugins .credentials .SecretBytes ;
910import com .cloudbees .plugins .credentials .impl .CertificateCredentialsImpl ;
1011import com .cloudbees .plugins .credentials .impl .UsernamePasswordCredentialsImpl ;
11- import edu .umd .cs .findbugs .annotations .NonNull ;
12+ import java .io .ByteArrayOutputStream ;
13+ import java .security .KeyStore ;
1214import java .util .Collections ;
1315import java .util .List ;
16+ import java .util .UUID ;
1417import jenkins .authentication .tokens .api .AuthenticationTokenContext ;
1518import jenkins .authentication .tokens .api .AuthenticationTokens ;
1619import org .junit .ClassRule ;
@@ -57,7 +60,7 @@ public void authenticationContextTest() {
5760 }
5861
5962 @ Test
60- public void passwordCredentialsTest () {
63+ public void passwordCredentialsTest () throws Exception {
6164 List <Credentials > list = Collections .<Credentials >singletonList (new UsernamePasswordCredentialsImpl (
6265 CredentialsScope .SYSTEM , "dummy" , "dummy" , "user" , "pass" ));
6366 AuthenticationTokenContext ctx = BitbucketAuthenticator .authenticationContext ((null ));
@@ -69,9 +72,11 @@ public void passwordCredentialsTest() {
6972 }
7073
7174 @ 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 ();
7378 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 )));
7580
7681 AuthenticationTokenContext ctx = BitbucketAuthenticator .authenticationContext (null );
7782 Credentials c = CredentialsMatchers .firstOrNull (list , AuthenticationTokens .matcher (ctx ));
@@ -87,15 +92,20 @@ public void certCredentialsTest() {
8792 assertThat (AuthenticationTokens .convert (ctx , c ), notNullValue ());
8893 }
8994
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 {
9496
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+ }
97108
98- @ Override
99- public boolean isSnapshotSource () { return true ; }
100109 }
110+
101111}
0 commit comments