1+ /**
2+ * Licensed to the Apache Software Foundation (ASF) under one
3+ * or more contributor license agreements. See the NOTICE file
4+ * distributed with this work for additional information
5+ * regarding copyright ownership. The ASF licenses this file
6+ * to you under the Apache License, Version 2.0 (the
7+ * "License"); you may not use this file except in compliance
8+ * with the License. You may obtain a copy of the License at
9+ *
10+ * http://www.apache.org/licenses/LICENSE-2.0
11+ *
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+ */
118package org .apache .hadoop .security ;
219
320import java .net .InetAddress ;
421import java .net .InetSocketAddress ;
22+ import java .util .Map ;
523import javax .security .sasl .Sasl ;
624
725import org .junit .Before ;
826import org .junit .Test ;
927
1028import org .apache .hadoop .conf .Configuration ;
29+ import org .apache .hadoop .test .AbstractHadoopTestBase ;
1130
1231import static org .apache .hadoop .fs .CommonConfigurationKeysPublic .HADOOP_RPC_PROTECTION ;
1332import static org .junit .Assert .assertEquals ;
1433
15- public class TestSaslPropertiesResolver {
34+ public class TestSaslPropertiesResolver extends AbstractHadoopTestBase {
1635
17- private static final SaslRpcServer .QualityOfProtection PRIVACY_QOP = SaslRpcServer .QualityOfProtection .PRIVACY ;
18- private static final SaslRpcServer .QualityOfProtection AUTHENTICATION_QOP = SaslRpcServer .QualityOfProtection .AUTHENTICATION ;
1936 private static final InetAddress LOCALHOST = new InetSocketAddress ("127.0.0.1" , 1 ).getAddress ();
2037
2138 private SaslPropertiesResolver resolver ;
@@ -30,20 +47,29 @@ public void setup() {
3047
3148 @ Test
3249 public void testResolverDoesNotMutate () {
33- assertEquals (PRIVACY_QOP .getSaslQop (), resolver .getDefaultProperties ().get (Sasl .QOP ));
34- resolver .getDefaultProperties ().put (Sasl .QOP , AUTHENTICATION_QOP .getSaslQop ());
35- // Even after changing the map returned by SaslPropertiesResolver, it does not change its future responses
36- assertEquals (PRIVACY_QOP .getSaslQop (), resolver .getDefaultProperties ().get (Sasl .QOP ));
37-
38- assertEquals (PRIVACY_QOP .getSaslQop (), resolver .getClientProperties (LOCALHOST ).get (Sasl .QOP ));
39- resolver .getDefaultProperties ().put (Sasl .QOP , AUTHENTICATION_QOP .getSaslQop ());
40- // Even after changing the map returned by SaslPropertiesResolver, it does not change its future responses
41- assertEquals (PRIVACY_QOP .getSaslQop (), resolver .getClientProperties (LOCALHOST ).get (Sasl .QOP ));
42-
43- assertEquals (PRIVACY_QOP .getSaslQop (), resolver .getServerProperties (LOCALHOST ).get (Sasl .QOP ));
44- resolver .getDefaultProperties ().put (Sasl .QOP , AUTHENTICATION_QOP .getSaslQop ());
45- // Even after changing the map returned by SaslPropertiesResolver, it does not change its future responses
46- assertEquals (PRIVACY_QOP .getSaslQop (), resolver .getServerProperties (LOCALHOST ).get (Sasl .QOP ));
50+ assertPrivacyQop (resolver .getDefaultProperties ());
51+ setAuthenticationQop (resolver .getDefaultProperties ());
52+ // After changing the map returned by SaslPropertiesResolver, future maps are not affected
53+ assertPrivacyQop (resolver .getDefaultProperties ());
54+
55+ assertPrivacyQop (resolver .getClientProperties (LOCALHOST ));
56+ setAuthenticationQop (resolver .getClientProperties (LOCALHOST ));
57+ // After changing the map returned by SaslPropertiesResolver, future maps are not affected
58+ assertPrivacyQop (resolver .getClientProperties (LOCALHOST ));
59+
60+ assertPrivacyQop (resolver .getServerProperties (LOCALHOST ));
61+ setAuthenticationQop (resolver .getServerProperties (LOCALHOST ));
62+ // After changing the map returned by SaslPropertiesResolver, future maps are not affected
63+ assertPrivacyQop (resolver .getServerProperties (LOCALHOST ));
64+ }
65+
66+ private static void setAuthenticationQop (Map <String , String > saslProperties ) {
67+ saslProperties .put (Sasl .QOP , SaslRpcServer .QualityOfProtection .AUTHENTICATION .getSaslQop ());
68+ }
69+
70+ private static void assertPrivacyQop (Map <String , String > saslProperties ) {
71+ assertEquals (SaslRpcServer .QualityOfProtection .PRIVACY .getSaslQop (),
72+ saslProperties .get (Sasl .QOP ));
4773 }
4874
4975}
0 commit comments