/
BlockWorkerClientAuthenticationIntegrationTest.java
122 lines (105 loc) · 4.32 KB
/
BlockWorkerClientAuthenticationIntegrationTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*
* The Alluxio Open Foundation licenses this work under the Apache License, version 2.0
* (the "License"). You may not use this work except in compliance with the License, which is
* available at www.apache.org/licenses/LICENSE-2.0
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied, as more fully set forth in the License.
*
* See the NOTICE file distributed with this work for information regarding copyright ownership.
*/
package alluxio.security;
import alluxio.Constants;
import alluxio.LocalAlluxioClusterResource;
import alluxio.client.block.BlockWorkerClient;
import alluxio.client.block.DefaultBlockWorkerClient;
import alluxio.client.util.ClientTestUtils;
import alluxio.security.MasterClientAuthenticationIntegrationTest.NameMatchAuthenticationProvider;
import alluxio.worker.ClientMetrics;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import java.io.IOException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
/**
* Tests RPC authentication between worker and its client, in four modes: NOSASL, SIMPLE, CUSTOM,
* KERBEROS.
*/
// TODO(bin): improve the way to set and isolate MasterContext/WorkerContext across test cases
public final class BlockWorkerClientAuthenticationIntegrationTest {
@Rule
public LocalAlluxioClusterResource mLocalAlluxioClusterResource =
new LocalAlluxioClusterResource();
private ExecutorService mExecutorService;
@Rule
public ExpectedException mThrown = ExpectedException.none();
@Before
public void before() throws Exception {
mExecutorService = Executors.newFixedThreadPool(2);
clearLoginUser();
}
@After
public void after() throws Exception {
clearLoginUser();
mExecutorService.shutdownNow();
}
@Test
@LocalAlluxioClusterResource.Config(
confParams = {Constants.SECURITY_AUTHENTICATION_TYPE, "NOSASL"})
public void noAuthenticationOpenCloseTest() throws Exception {
authenticationOperationTest();
}
@Test
@LocalAlluxioClusterResource.Config(
confParams = {Constants.SECURITY_AUTHENTICATION_TYPE, "SIMPLE"})
public void simpleAuthenticationOpenCloseTest() throws Exception {
authenticationOperationTest();
}
@Test
@LocalAlluxioClusterResource.Config(
confParams = {Constants.SECURITY_AUTHENTICATION_TYPE, "CUSTOM",
Constants.SECURITY_AUTHENTICATION_CUSTOM_PROVIDER,
NameMatchAuthenticationProvider.FULL_CLASS_NAME,
Constants.SECURITY_LOGIN_USERNAME, "alluxio"})
public void customAuthenticationOpenCloseTest() throws Exception {
authenticationOperationTest();
}
@Test(timeout = 10000)
@LocalAlluxioClusterResource.Config(confParams = {Constants.SECURITY_AUTHENTICATION_TYPE,
"CUSTOM", Constants.SECURITY_AUTHENTICATION_CUSTOM_PROVIDER,
NameMatchAuthenticationProvider.FULL_CLASS_NAME,
Constants.SECURITY_LOGIN_USERNAME, "alluxio"})
public void customAuthenticationDenyConnectTest() throws Exception {
mThrown.expect(IOException.class);
mThrown.expectMessage("Failed to connect to the worker");
try (BlockWorkerClient blockWorkerClient = new DefaultBlockWorkerClient(
mLocalAlluxioClusterResource.get().getWorkerAddress(), mExecutorService,
1 /* fake session id */, true, new ClientMetrics())) {
Assert.assertFalse(blockWorkerClient.isConnected());
// Using no-alluxio as loginUser to connect to Worker, the IOException will be thrown
LoginUserTestUtils.resetLoginUser("no-alluxio");
blockWorkerClient.connect();
} finally {
ClientTestUtils.resetClient();
}
}
/**
* Tests Alluxio Worker client connects or disconnects to the Worker.
*/
private void authenticationOperationTest() throws Exception {
DefaultBlockWorkerClient blockWorkerClient = new DefaultBlockWorkerClient(
mLocalAlluxioClusterResource.get().getWorkerAddress(),
mExecutorService, 1 /* fake session id */, true, new ClientMetrics());
Assert.assertFalse(blockWorkerClient.isConnected());
blockWorkerClient.connect();
Assert.assertTrue(blockWorkerClient.isConnected());
blockWorkerClient.close();
}
private void clearLoginUser() throws Exception {
LoginUserTestUtils.resetLoginUser();
}
}