-
Notifications
You must be signed in to change notification settings - Fork 980
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DRILL-6088: MainLoginPageModel errors out when http.auth.mechanisms i…
…s not configured DRILL-6088: Update based on review feedback close #1092
- Loading branch information
Sorabh Hamirwasia
authored and
Aman Sinha
committed
Jan 21, 2018
1 parent
dbaf048
commit a2a56af
Showing
4 changed files
with
211 additions
and
48 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
133 changes: 133 additions & 0 deletions
133
exec/java-exec/src/test/java/org/apache/drill/exec/server/rest/TestMainLoginPageModel.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,133 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.drill.exec.server.rest; | ||
|
||
import com.google.common.collect.Lists; | ||
import com.typesafe.config.ConfigValueFactory; | ||
import org.apache.drill.common.config.DrillConfig; | ||
import org.apache.drill.exec.ExecConstants; | ||
import org.apache.drill.exec.server.DrillbitContext; | ||
import org.apache.drill.exec.server.rest.LogInLogOutResources.MainLoginPageModel; | ||
import org.apache.drill.exec.work.WorkManager; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.MockitoAnnotations; | ||
|
||
import static junit.framework.TestCase.assertTrue; | ||
import static org.mockito.Mockito.when; | ||
|
||
/** | ||
* Test for {@link LogInLogOutResources.MainLoginPageModel} with various configurations done in DrillConfig | ||
*/ | ||
public class TestMainLoginPageModel { | ||
|
||
@Mock | ||
WorkManager workManager; | ||
|
||
@Mock | ||
DrillbitContext context; | ||
|
||
@InjectMocks | ||
LogInLogOutResources logInLogOutResources = new LogInLogOutResources(); | ||
|
||
@Before | ||
public void setup() { | ||
MockitoAnnotations.initMocks(this); | ||
when(workManager.getContext()).thenReturn(context); | ||
} | ||
|
||
/** | ||
* Test when auth is disabled then both Form and Spnego authentication is disabled. | ||
*/ | ||
@Test | ||
public void testAuthDisabled() { | ||
final DrillConfig config = DrillConfig.create(); | ||
when(context.getConfig()).thenReturn(config); | ||
final MainLoginPageModel model = logInLogOutResources.new MainLoginPageModel(null); | ||
assertTrue(!model.isFormEnabled()); | ||
assertTrue(!model.isSpnegoEnabled()); | ||
} | ||
|
||
/** | ||
* Test when auth is enabled with no http.auth.mechanisms configured then by default Form authentication is | ||
* enabled but Spnego is disabled. | ||
*/ | ||
@Test | ||
public void testAuthEnabledWithNoMech() { | ||
final DrillConfig config = new DrillConfig(DrillConfig.create() | ||
.withValue(ExecConstants.USER_AUTHENTICATION_ENABLED, | ||
ConfigValueFactory.fromAnyRef(true)), false); | ||
when(context.getConfig()).thenReturn(config); | ||
final MainLoginPageModel model = logInLogOutResources.new MainLoginPageModel(null); | ||
assertTrue(model.isFormEnabled()); | ||
assertTrue(!model.isSpnegoEnabled()); | ||
} | ||
|
||
/** | ||
* Test when auth is enabled with http.auth.mechanisms configured as Form then only Form authentication is | ||
* enabled but Spnego is disabled. | ||
*/ | ||
@Test | ||
public void testAuthEnabledWithForm() { | ||
final DrillConfig config = new DrillConfig(DrillConfig.create() | ||
.withValue(ExecConstants.USER_AUTHENTICATION_ENABLED, | ||
ConfigValueFactory.fromAnyRef(true)) | ||
.withValue(ExecConstants.HTTP_AUTHENTICATION_MECHANISMS, | ||
ConfigValueFactory.fromIterable(Lists.newArrayList("form"))), false); | ||
when(context.getConfig()).thenReturn(config); | ||
final MainLoginPageModel model = logInLogOutResources.new MainLoginPageModel(null); | ||
assertTrue(model.isFormEnabled()); | ||
assertTrue(!model.isSpnegoEnabled()); | ||
} | ||
|
||
/** | ||
* Test when auth is enabled with http.auth.mechanisms configured as Spnego then only Spnego authentication is | ||
* enabled but Form is disabled. | ||
*/ | ||
@Test | ||
public void testAuthEnabledWithSpnego() { | ||
final DrillConfig config = new DrillConfig(DrillConfig.create() | ||
.withValue(ExecConstants.USER_AUTHENTICATION_ENABLED, | ||
ConfigValueFactory.fromAnyRef(true)) | ||
.withValue(ExecConstants.HTTP_AUTHENTICATION_MECHANISMS, | ||
ConfigValueFactory.fromIterable(Lists.newArrayList("spnego"))), false); | ||
when(context.getConfig()).thenReturn(config); | ||
final MainLoginPageModel model = logInLogOutResources.new MainLoginPageModel(null); | ||
assertTrue(!model.isFormEnabled()); | ||
assertTrue(model.isSpnegoEnabled()); | ||
} | ||
|
||
/** | ||
* Test when auth is enabled with http.auth.mechanisms configured as Form, Spnego then both Form and Spnego | ||
* authentication are enabled. | ||
*/ | ||
@Test | ||
public void testAuthEnabledWithFormSpnego() { | ||
final DrillConfig config = new DrillConfig(DrillConfig.create() | ||
.withValue(ExecConstants.USER_AUTHENTICATION_ENABLED, | ||
ConfigValueFactory.fromAnyRef(true)) | ||
.withValue(ExecConstants.HTTP_AUTHENTICATION_MECHANISMS, | ||
ConfigValueFactory.fromIterable(Lists.newArrayList("form", "spnego"))), false); | ||
when(context.getConfig()).thenReturn(config); | ||
final MainLoginPageModel model = logInLogOutResources.new MainLoginPageModel(null); | ||
assertTrue(model.isFormEnabled()); | ||
assertTrue(model.isSpnegoEnabled()); | ||
} | ||
} |