| /** |
| * Licensed 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 io.streamnative.pulsar.manager.service; |
| |
| import io.jsonwebtoken.Claims; |
| import io.streamnative.pulsar.manager.PulsarManagerApplication; |
| import io.streamnative.pulsar.manager.profiles.HerdDBTestProfile; |
| import org.junit.Assert; |
| import org.junit.Test; |
| import org.junit.runner.RunWith; |
| import org.powermock.core.classloader.annotations.PowerMockIgnore; |
| import org.powermock.modules.junit4.PowerMockRunner; |
| import org.powermock.modules.junit4.PowerMockRunnerDelegate; |
| import org.springframework.beans.factory.annotation.Autowired; |
| import org.springframework.boot.test.context.SpringBootTest; |
| import org.springframework.test.context.ActiveProfiles; |
| import org.springframework.test.context.TestPropertySource; |
| import org.springframework.test.context.junit4.SpringRunner; |
| |
| @RunWith(PowerMockRunner.class) |
| @PowerMockRunnerDelegate(SpringRunner.class) |
| @PowerMockIgnore( {"javax.*", "sun.*", "com.sun.*", "org.xml.*", "org.w3c.*"}) |
| @TestPropertySource( |
| properties = { |
| "jwt.broker.token.mode=SECRET", |
| "jwt.broker.secret.key=data:base64,cxkc+xPbcF/3E49I1HE4BJKtAwZ/FUER1h7wXk7qkLw=" |
| } |
| ) |
| @SpringBootTest( |
| classes = { |
| PulsarManagerApplication.class, |
| HerdDBTestProfile.class |
| } |
| ) |
| @ActiveProfiles("test") |
| public class BrokerTokensServiceImplTest { |
| |
| @Autowired |
| private JwtService jwtService; |
| |
| @Test |
| public void createBrokerTokenTest() { |
| String role = "test"; |
| String token = jwtService.createBrokerToken(role, null); |
| Claims jwtBody = jwtService.validateBrokerToken(token); |
| Assert.assertEquals(jwtBody.getSubject(), role); |
| } |
| } |