-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Sergii Kabashniuk <skabashniuk@redhat.com>
- Loading branch information
1 parent
4699856
commit 42a26d9
Showing
5 changed files
with
175 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
...-server/src/test/java/org/eclipse/che/security/oauth1/BitbucketServerApiProviderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
/* | ||
* Copyright (c) 2012-2018 Red Hat, Inc. | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
*/ | ||
package org.eclipse.che.security.oauth1; | ||
|
||
import static org.testng.Assert.assertNotNull; | ||
import static org.testng.Assert.assertTrue; | ||
|
||
import com.google.common.collect.ImmutableSet; | ||
import java.io.IOException; | ||
import java.util.Collections; | ||
import java.util.Set; | ||
import org.eclipse.che.api.factory.server.bitbucket.server.BitbucketServerApi; | ||
import org.eclipse.che.api.factory.server.bitbucket.server.BitbucketServerApiHttpClient; | ||
import org.eclipse.che.api.factory.server.bitbucket.server.NopBitbucketServerApi; | ||
import org.eclipse.che.commons.annotation.Nullable; | ||
import org.testng.annotations.BeforeClass; | ||
import org.testng.annotations.DataProvider; | ||
import org.testng.annotations.Test; | ||
|
||
public class BitbucketServerApiProviderTest { | ||
BitbucketServerOAuthAuthenticator oAuthAuthenticator; | ||
|
||
@BeforeClass | ||
public void setUp() { | ||
oAuthAuthenticator = | ||
new BitbucketServerOAuthAuthenticator( | ||
"df", "private", " https://bitbucket2.server.com", " https://che.server.com"); | ||
} | ||
|
||
@Test | ||
public void shouldBeAbleToCreateBitbucketServerApi() { | ||
// given | ||
BitbucketServerApiProvider bitbucketServerApiProvider = | ||
new BitbucketServerApiProvider( | ||
"https://bitbucket.server.com, https://bitbucket2.server.com", | ||
"https://bitbucket.server.com", | ||
ImmutableSet.of(oAuthAuthenticator)); | ||
// when | ||
BitbucketServerApi actual = bitbucketServerApiProvider.get(); | ||
// then | ||
assertNotNull(actual); | ||
assertTrue(BitbucketServerApiHttpClient.class.isAssignableFrom(actual.getClass())); | ||
} | ||
|
||
@Test(dataProvider = "noopConfig") | ||
public void shouldProvideNoopOAuthAuthenticatorIfSomeConfigurationIsNotSet( | ||
@Nullable String bitbucketEndpoints, | ||
@Nullable String bitbucketOauth1Endpoint, | ||
Set<OAuthAuthenticator> authenticators) | ||
throws IOException { | ||
// given | ||
BitbucketServerApiProvider bitbucketServerApiProvider = | ||
new BitbucketServerApiProvider(bitbucketEndpoints, bitbucketOauth1Endpoint, authenticators); | ||
// when | ||
BitbucketServerApi actual = bitbucketServerApiProvider.get(); | ||
// then | ||
assertNotNull(actual); | ||
assertTrue(NopBitbucketServerApi.class.isAssignableFrom(actual.getClass())); | ||
} | ||
|
||
@Test( | ||
expectedExceptions = RuntimeException.class, | ||
expectedExceptionsMessageRegExp = | ||
"`che.integration.bitbucket.server_endpoints` bitbucket configuration is missing. It should contain values from 'che.oauth1.bitbucket.endpoint'") | ||
public void shouldFailToBuildIfEndpointsAreMisconfigured() { | ||
// given | ||
// when | ||
BitbucketServerApiProvider bitbucketServerApiProvider = | ||
new BitbucketServerApiProvider( | ||
"", "https://bitbucket.server.com", ImmutableSet.of(oAuthAuthenticator)); | ||
} | ||
|
||
@Test( | ||
expectedExceptions = RuntimeException.class, | ||
expectedExceptionsMessageRegExp = | ||
"'che.oauth1.bitbucket.endpoint' is set but BitbucketServerOAuthAuthenticator deployed correctly") | ||
public void shouldFailToBuildIfEndpointsAreMisconfigured2() { | ||
// given | ||
// when | ||
BitbucketServerApiProvider bitbucketServerApiProvider = | ||
new BitbucketServerApiProvider( | ||
"https://bitbucket.server.com, https://bitbucket2.server.com", | ||
"https://bitbucket.server.com", | ||
Collections.emptySet()); | ||
} | ||
|
||
@Test( | ||
expectedExceptions = RuntimeException.class, | ||
expectedExceptionsMessageRegExp = | ||
"`che.integration.bitbucket.server_endpoints` mast contain `https://bitbucket.server.com` value") | ||
public void shouldFailToBuildIfEndpointsAreMisconfigured3() { | ||
// given | ||
// when | ||
BitbucketServerApiProvider bitbucketServerApiProvider = | ||
new BitbucketServerApiProvider( | ||
"https://bitbucket3.server.com, https://bitbucket2.server.com", | ||
"https://bitbucket.server.com", | ||
ImmutableSet.of(oAuthAuthenticator)); | ||
} | ||
|
||
@DataProvider(name = "noopConfig") | ||
public Object[][] noopConfig() { | ||
return new Object[][] { | ||
{null, null, null}, | ||
{"https://bitbucket.server.com, https://bitbucket2.server.com", null, null}, | ||
{ | ||
"https://bitbucket.server.com, https://bitbucket2.server.com", | ||
null, | ||
ImmutableSet.of(oAuthAuthenticator) | ||
} | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters