1 /*******************************************************************************
2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 * ============LICENSE_END=========================================================
20 *******************************************************************************/
21 package org.onap.dmaap.kafkaAuthorize;
23 import static org.junit.Assert.assertNotNull;
25 import javax.security.sasl.SaslException;
27 import org.apache.kafka.common.security.JaasContext;
28 import org.apache.kafka.common.security.plain.PlainSaslServer;
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.junit.runner.RunWith;
32 import org.mockito.Mock;
33 import org.mockito.MockitoAnnotations;
34 import org.onap.dmaap.commonauth.kafka.base.authorization.AuthorizationProvider;
35 import org.onap.dmaap.commonauth.kafka.base.authorization.AuthorizationProviderFactory;
36 import org.powermock.api.mockito.PowerMockito;
37 import org.powermock.core.classloader.annotations.PrepareForTest;
38 import org.powermock.modules.junit4.PowerMockRunner;
40 @RunWith(PowerMockRunner.class)
41 @PrepareForTest({ AuthorizationProviderFactory.class })
42 public class PlainSaslServer1Test {
44 PlainSaslServer1 sslServer = new PlainSaslServer1(null);
46 JaasContext jaasContext;
48 AuthorizationProviderFactory factory;
50 AuthorizationProvider provider;
53 public void setUp() throws Exception {
55 MockitoAnnotations.initMocks(this);
56 PowerMockito.mockStatic(AuthorizationProviderFactory.class);
57 PowerMockito.when(AuthorizationProviderFactory.getProviderFactory()).thenReturn(factory);
58 PowerMockito.when(factory.getProvider()).thenReturn(provider);
62 public void testAuthentication() throws Exception {
63 String response = "authorizationID\u0000username\u0000password";
64 PowerMockito.when(provider.authenticate("username", "password")).thenReturn(null);
65 assertNotNull(sslServer.evaluateResponse(response.getBytes()));