Skip to content

Commit 42c6a31

Browse files
LukasInnerhoferLukasInnerhoferPalfingerlifeofguenter
authored
Feature/enable access tokens for cloud (#761)
* Enabled bitbucket access tokens for cloud instance * Testing isFit for both server and cloud HTTPS instances * Added crosscheck with HTTP source --------- Co-authored-by: Lukas Innerhofer <[email protected]> Co-authored-by: Günter Grodotzki <[email protected]>
1 parent 39f98d0 commit 42c6a31

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/main/java/com/cloudbees/jenkins/plugins/bitbucket/api/credentials/BitbucketAccessTokenAuthenticatorSource.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public BitbucketAccessTokenAuthenticator convert(@NonNull StringCredentials cred
4141
@Override
4242
public boolean isFit(AuthenticationTokenContext ctx) {
4343
return ctx.mustHave(BitbucketAuthenticator.SCHEME, "https")
44-
&& ctx.mustHave(BitbucketAuthenticator.BITBUCKET_INSTANCE_TYPE, BitbucketAuthenticator.BITBUCKET_INSTANCE_TYPE_SERVER);
44+
&& (ctx.mustHave(BitbucketAuthenticator.BITBUCKET_INSTANCE_TYPE, BitbucketAuthenticator.BITBUCKET_INSTANCE_TYPE_SERVER)
45+
|| ctx.mustHave(BitbucketAuthenticator.BITBUCKET_INSTANCE_TYPE, BitbucketAuthenticator.BITBUCKET_INSTANCE_TYPE_CLOUD));
4546
}
4647
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.cloudbees.jenkins.plugins.bitbucket.api.credentials;
2+
3+
import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketAuthenticator;
4+
import jenkins.authentication.tokens.api.AuthenticationTokenContext;
5+
import org.junit.ClassRule;
6+
import org.junit.Test;
7+
import org.jvnet.hudson.test.JenkinsRule;
8+
9+
import static org.hamcrest.Matchers.is;
10+
import static org.hamcrest.MatcherAssert.assertThat;
11+
12+
public class BitbucketAccessTokenAuthenticatorSourceTest {
13+
@ClassRule
14+
public static JenkinsRule j = new JenkinsRule();
15+
16+
@Test
17+
public void isFitTest() {
18+
BitbucketAccessTokenAuthenticatorSource source = new BitbucketAccessTokenAuthenticatorSource();
19+
AuthenticationTokenContext<BitbucketAuthenticator> cloudContext = BitbucketAuthenticator.authenticationContext("https://bitbucket.org");
20+
AuthenticationTokenContext<BitbucketAuthenticator> serverContext = BitbucketAuthenticator.authenticationContext("https://bitbucket-server.org");
21+
AuthenticationTokenContext<BitbucketAuthenticator> unsecureServerContext = BitbucketAuthenticator.authenticationContext("http://bitbucket-server.org");
22+
assertThat(source.isFit(cloudContext), is(true));
23+
assertThat(source.isFit(serverContext), is(true));
24+
assertThat(source.isFit(unsecureServerContext), is(false));
25+
}
26+
}

0 commit comments

Comments
 (0)