/// <exception cref="System.Exception"/> public virtual void TestLoginObjectInSubject() { UserGroupInformation loginUgi = UserGroupInformation.GetLoginUser(); UserGroupInformation anotherUgi = new UserGroupInformation(loginUgi.GetSubject()); LoginContext login1 = loginUgi.GetSubject().GetPrincipals <User>().GetEnumerator() .Next().GetLogin(); LoginContext login2 = anotherUgi.GetSubject().GetPrincipals <User>().GetEnumerator ().Next().GetLogin(); //login1 and login2 must be same instances Assert.True(login1 == login2); }
/// <exception cref="System.Exception"/> public virtual void TestLoginModuleCommit() { UserGroupInformation loginUgi = UserGroupInformation.GetLoginUser(); User user1 = loginUgi.GetSubject().GetPrincipals <User>().GetEnumerator().Next(); LoginContext login = user1.GetLogin(); login.Logout(); login.Login(); User user2 = loginUgi.GetSubject().GetPrincipals <User>().GetEnumerator().Next(); // user1 and user2 must be same instances. Assert.True(user1 == user2); }
/// <exception cref="System.Exception"/> public virtual void TestUGIAuthMethodInRealUser() { UserGroupInformation ugi = UserGroupInformation.GetCurrentUser(); UserGroupInformation proxyUgi = UserGroupInformation.CreateProxyUser("proxy", ugi ); UserGroupInformation.AuthenticationMethod am = UserGroupInformation.AuthenticationMethod .Kerberos; ugi.SetAuthenticationMethod(am); Assert.Equal(am, ugi.GetAuthenticationMethod()); Assert.Equal(UserGroupInformation.AuthenticationMethod.Proxy, proxyUgi.GetAuthenticationMethod()); Assert.Equal(am, UserGroupInformation.GetRealAuthenticationMethod (proxyUgi)); proxyUgi.DoAs(new _PrivilegedExceptionAction_690(am)); UserGroupInformation proxyUgi2 = new UserGroupInformation(proxyUgi.GetSubject()); proxyUgi2.SetAuthenticationMethod(UserGroupInformation.AuthenticationMethod.Proxy ); Assert.Equal(proxyUgi, proxyUgi2); // Equality should work if authMethod is null UserGroupInformation realugi = UserGroupInformation.GetCurrentUser(); UserGroupInformation proxyUgi3 = UserGroupInformation.CreateProxyUser("proxyAnother" , realugi); UserGroupInformation proxyUgi4 = new UserGroupInformation(proxyUgi3.GetSubject()); Assert.Equal(proxyUgi3, proxyUgi4); }
/// <exception cref="System.Exception"/> public virtual void TestEqualsWithRealUser() { UserGroupInformation realUgi1 = UserGroupInformation.CreateUserForTesting("RealUser" , GroupNames); UserGroupInformation proxyUgi1 = UserGroupInformation.CreateProxyUser(UserName, realUgi1 ); UserGroupInformation proxyUgi2 = new UserGroupInformation(proxyUgi1.GetSubject()); UserGroupInformation remoteUgi = UserGroupInformation.CreateRemoteUser(UserName); Assert.Equal(proxyUgi1, proxyUgi2); NUnit.Framework.Assert.IsFalse(remoteUgi.Equals(proxyUgi1)); }
/// <exception cref="System.Exception"/> public virtual void TestEquals() { UserGroupInformation uugi = UserGroupInformation.CreateUserForTesting(UserName, GroupNames ); Assert.Equal(uugi, uugi); // The subjects should be different, so this should fail UserGroupInformation ugi2 = UserGroupInformation.CreateUserForTesting(UserName, GroupNames ); NUnit.Framework.Assert.IsFalse(uugi.Equals(ugi2)); NUnit.Framework.Assert.IsFalse(uugi.GetHashCode() == ugi2.GetHashCode()); // two ugi that have the same subject need to be equal UserGroupInformation ugi3 = new UserGroupInformation(uugi.GetSubject()); Assert.Equal(uugi, ugi3); Assert.Equal(uugi.GetHashCode(), ugi3.GetHashCode()); }
public virtual void TestUGILoginFromKeytab() { UserGroupInformation.SetShouldRenewImmediatelyForTests(true); string principal = "foo"; FilePath keytab = new FilePath(workDir, "foo.keytab"); kdc.CreatePrincipal(keytab, principal); UserGroupInformation.LoginUserFromKeytab(principal, keytab.GetPath()); UserGroupInformation ugi = UserGroupInformation.GetLoginUser(); Assert.True("UGI should be configured to login from keytab", ugi .IsFromKeytab()); // Verify relogin from keytab. User user = ugi.GetSubject().GetPrincipals <User>().GetEnumerator().Next(); long firstLogin = user.GetLastLogin(); ugi.ReloginFromKeytab(); long secondLogin = user.GetLastLogin(); Assert.True("User should have been able to relogin from keytab" , secondLogin > firstLogin); }