Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Licensed to the Apache Software Foundation (ASF) under one or more
0003  * contributor license agreements.  See the NOTICE file distributed with
0004  * this work for additional information regarding copyright ownership.
0005  * The ASF licenses this file to You under the Apache License, Version 2.0
0006  * (the "License"); you may not use this file except in compliance with
0007  * the License.  You may obtain a copy of the License at
0008  *
0009  *    http://www.apache.org/licenses/LICENSE-2.0
0010  *
0011  * Unless required by applicable law or agreed to in writing, software
0012  * distributed under the License is distributed on an "AS IS" BASIS,
0013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014  * See the License for the specific language governing permissions and
0015  * limitations under the License.
0016  */
0017 
0018 package org.apache.spark.network.sasl;
0019 
0020 import java.nio.ByteBuffer;
0021 
0022 import org.junit.Test;
0023 import static org.junit.Assert.*;
0024 
0025 public class ShuffleSecretManagerSuite {
0026   static String app1 = "app1";
0027   static String app2 = "app2";
0028   static String pw1 = "password1";
0029   static String pw2 = "password2";
0030   static String pw1update = "password1update";
0031   static String pw2update = "password2update";
0032 
0033   @Test
0034   public void testMultipleRegisters() {
0035     ShuffleSecretManager secretManager = new ShuffleSecretManager();
0036     secretManager.registerApp(app1, pw1);
0037     assertEquals(pw1, secretManager.getSecretKey(app1));
0038     secretManager.registerApp(app2, ByteBuffer.wrap(pw2.getBytes()));
0039     assertEquals(pw2, secretManager.getSecretKey(app2));
0040 
0041     // now update the password for the apps and make sure it takes affect
0042     secretManager.registerApp(app1, pw1update);
0043     assertEquals(pw1update, secretManager.getSecretKey(app1));
0044     secretManager.registerApp(app2, ByteBuffer.wrap(pw2update.getBytes()));
0045     assertEquals(pw2update, secretManager.getSecretKey(app2));
0046 
0047     secretManager.unregisterApp(app1);
0048     assertNull(secretManager.getSecretKey(app1));
0049     assertEquals(pw2update, secretManager.getSecretKey(app2));
0050 
0051     secretManager.unregisterApp(app2);
0052     assertNull(secretManager.getSecretKey(app2));
0053     assertNull(secretManager.getSecretKey(app1));
0054   }
0055 }