-
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.
Added tests for BitbucketServerOAuthAuthenticatorProvider.
Signed-off-by: Sergii Kabashniuk <skabashniuk@redhat.com>
- Loading branch information
1 parent
222aaf7
commit 4699856
Showing
4 changed files
with
122 additions
and
1 deletion.
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
83 changes: 83 additions & 0 deletions
83
...t/java/org/eclipse/che/security/oauth1/BitbucketServerOAuthAuthenticatorProviderTest.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,83 @@ | ||
/* | ||
* 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.io.Files; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.charset.Charset; | ||
import org.testng.annotations.BeforeClass; | ||
import org.testng.annotations.DataProvider; | ||
import org.testng.annotations.Test; | ||
|
||
public class BitbucketServerOAuthAuthenticatorProviderTest { | ||
private File cfgFile; | ||
private File emptyFile; | ||
|
||
@BeforeClass | ||
public void setup() throws IOException { | ||
cfgFile = File.createTempFile("BitbucketServerOAuthAuthenticatorProviderTest-", "-cfg"); | ||
Files.asCharSink(cfgFile, Charset.defaultCharset()).write("tmp-data"); | ||
cfgFile.deleteOnExit(); | ||
emptyFile = File.createTempFile("BitbucketServerOAuthAuthenticatorProviderTest-", "-empty"); | ||
emptyFile.deleteOnExit(); | ||
} | ||
|
||
@Test(dataProvider = "noopConfig") | ||
public void shouldProvideNoopOAuthAuthenticatorIfSomeConfigurationIsNotSet( | ||
String consumerKeyPath, String privateKeyPath, String bitbucketEndpoint) throws IOException { | ||
// given | ||
BitbucketServerOAuthAuthenticatorProvider provider = | ||
new BitbucketServerOAuthAuthenticatorProvider( | ||
consumerKeyPath, privateKeyPath, bitbucketEndpoint, "http://che.server.com"); | ||
// when | ||
OAuthAuthenticator actual = provider.get(); | ||
// then | ||
assertNotNull(actual); | ||
assertTrue(NoopOAuthAuthenticator.class.isAssignableFrom(actual.getClass())); | ||
} | ||
|
||
@Test | ||
public void shouldBeAbleToConfigureValidBitbucketServerOAuthAuthenticator() throws IOException { | ||
// given | ||
BitbucketServerOAuthAuthenticatorProvider provider = | ||
new BitbucketServerOAuthAuthenticatorProvider( | ||
cfgFile.getPath(), cfgFile.getPath(), "http://bitubucket.com", "http://che.server.com"); | ||
// when | ||
OAuthAuthenticator actual = provider.get(); | ||
// then | ||
assertNotNull(actual); | ||
assertTrue(BitbucketServerOAuthAuthenticator.class.isAssignableFrom(actual.getClass())); | ||
} | ||
|
||
@DataProvider(name = "noopConfig") | ||
public Object[][] noopConfig() { | ||
return new Object[][] { | ||
{null, null, null}, | ||
{cfgFile.getPath(), null, null}, | ||
{null, cfgFile.getPath(), null}, | ||
{cfgFile.getPath(), cfgFile.getPath(), null}, | ||
{emptyFile.getPath(), null, null}, | ||
{null, emptyFile.getPath(), null}, | ||
{emptyFile.getPath(), emptyFile.getPath(), null}, | ||
{cfgFile.getPath(), emptyFile.getPath(), null}, | ||
{emptyFile.getPath(), cfgFile.getPath(), null}, | ||
{emptyFile.getPath(), emptyFile.getPath(), "http://bitubucket.com"}, | ||
{cfgFile.getPath(), emptyFile.getPath(), "http://bitubucket.com"}, | ||
{emptyFile.getPath(), cfgFile.getPath(), "http://bitubucket.com"}, | ||
{null, null, "http://bitubucket.com"} | ||
}; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
wsmaster/che-core-api-auth-bitbucket/src/test/resources/logback-test.xml
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,26 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
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 | ||
--> | ||
<configuration> | ||
|
||
<appender name="stdout" class="ch.qos.logback.core.ConsoleAppender"> | ||
<encoder> | ||
<pattern>%-41(%date[%.15thread]) %-45([%-5level] [%.30logger{30} %L]) - %msg%n</pattern> | ||
</encoder> | ||
</appender> | ||
<root level="INFO"> | ||
<appender-ref ref="stdout"/> | ||
</root> | ||
|
||
</configuration> |