Skip to content
This repository was archived by the owner on Dec 12, 2018. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.stormpath.sdk.application.ApplicationAccountStoreMappingList;
import com.stormpath.sdk.application.ApplicationAccountStoreMappings;
import com.stormpath.sdk.application.webconfig.ApplicationWebConfig;
import com.stormpath.sdk.application.webconfig.ApplicationWebConfigStatus;
import com.stormpath.sdk.directory.AccountStore;
import com.stormpath.sdk.directory.AccountStoreVisitor;
import com.stormpath.sdk.directory.Directory;
Expand Down Expand Up @@ -73,7 +74,7 @@ public List<AccountStoreModel> getAccountStores(HttpServletRequest request) {
@SuppressWarnings("WeakerAccess") // Want to allow overriding this method
protected String getAuthorizeBaseUri(@SuppressWarnings("UnusedParameters") HttpServletRequest request, ApplicationWebConfig webConfig) {
String authorizeBaseUri = null;
if (webConfig.getLogin().isEnabled()) {
if (webConfig.getStatus() == ApplicationWebConfigStatus.ENABLED && webConfig.getLogin().isEnabled()) {
authorizeBaseUri = "https://" + webConfig.getDomainName();
}
return authorizeBaseUri;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.stormpath.sdk.application.ApplicationAccountStoreMapping
import com.stormpath.sdk.application.ApplicationAccountStoreMappingCriteria
import com.stormpath.sdk.application.ApplicationAccountStoreMappingList
import com.stormpath.sdk.application.webconfig.ApplicationWebConfig
import com.stormpath.sdk.application.webconfig.ApplicationWebConfigStatus
import com.stormpath.sdk.application.webconfig.LoginConfig
import com.stormpath.sdk.directory.AccountStoreVisitor
import com.stormpath.sdk.directory.Directory
Expand All @@ -29,6 +30,7 @@ import static org.hamcrest.Matchers.containsString
import static org.hamcrest.Matchers.instanceOf
import static org.hamcrest.Matchers.nullValue
import static org.hamcrest.Matchers.startsWith
import static org.testng.Assert.assertNull

class ExternalAccountStoreModelFactoryTest {
static final String WEB_CONFIG_DOMAIN_NAME = "blah-blah.apps.stormpath.io"
Expand All @@ -39,6 +41,7 @@ class ExternalAccountStoreModelFactoryTest {
MockHttpServletRequest request
Application application
ApplicationWebConfig applicationWebConfig
ApplicationWebConfigStatus applicationWebConfigEnabled
LoginConfig loginConfig
boolean loginConfigEnabled

Expand Down Expand Up @@ -70,7 +73,14 @@ class ExternalAccountStoreModelFactoryTest {
return loginConfigEnabled
}
})
applicationWebConfigEnabled = ApplicationWebConfigStatus.DISABLED
applicationWebConfig = createNiceMock(ApplicationWebConfig)
expect(applicationWebConfig.getStatus()).andStubAnswer(new IAnswer<ApplicationWebConfigStatus>() {
@Override
ApplicationWebConfigStatus answer() throws Throwable {
return applicationWebConfigEnabled
}
})
expect(applicationWebConfig.login).andStubReturn(loginConfig)
expect(applicationWebConfig.domainName).andStubReturn(WEB_CONFIG_DOMAIN_NAME)

Expand Down Expand Up @@ -190,7 +200,8 @@ class ExternalAccountStoreModelFactoryTest {
}

@Test
void testOAuthAccountStoreMappingWithWebConfigLoginEnabled() {
void testOAuthAccountStoreMappingWithWebConfigEnabledLoginEnabled() {
applicationWebConfigEnabled = ApplicationWebConfigStatus.ENABLED
loginConfigEnabled = true
addMapping(facebookAccountStore)
def actual = factoryUT.getAccountStores(request)
Expand All @@ -203,6 +214,20 @@ class ExternalAccountStoreModelFactoryTest {
assertThat("authorizeUri", accountStoreModel.authorizeUri, startsWith("https://${WEB_CONFIG_DOMAIN_NAME}/authorize"))
}

// test to verify fix for https://github.com/stormpath/stormpath-sdk-java/issues/1159
@Test
void testOAuthAccountStoreMappingWithWebConfigDisabledLoginEnabled() {
applicationWebConfigEnabled = ApplicationWebConfigStatus.DISABLED
loginConfigEnabled = true
addMapping(facebookAccountStore)
def actual = factoryUT.getAccountStores(request)

assertThat(actual, Matchers.hasSize(1))
def accountStoreModel = actual[0]
assertThat(accountStoreModel.provider, instanceOf(DefaultOAuthProviderModel))
assertNull(accountStoreModel.authorizeUri)
}

private ApplicationAccountStoreMapping addMapping(Directory directory) {
ApplicationAccountStoreMapping mapping = createNiceMock(ApplicationAccountStoreMapping)
expect(mapping.application).andStubReturn(application)
Expand Down