You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@storm.apache.org by sr...@apache.org on 2015/03/12 18:06:54 UTC
[08/10] storm git commit: Fix failing unit test
Fix failing unit test
Project: http://git-wip-us.apache.org/repos/asf/storm/repo
Commit: http://git-wip-us.apache.org/repos/asf/storm/commit/22a81920
Tree: http://git-wip-us.apache.org/repos/asf/storm/tree/22a81920
Diff: http://git-wip-us.apache.org/repos/asf/storm/diff/22a81920
Branch: refs/heads/master
Commit: 22a81920fda6004388a48b5eecd1b103ed6cb3aa
Parents: 7314562
Author: Parth Brahmbhatt <br...@gmail.com>
Authored: Sun Mar 8 19:34:37 2015 -0700
Committer: Parth Brahmbhatt <br...@gmail.com>
Committed: Sun Mar 8 19:34:37 2015 -0700
----------------------------------------------------------------------
.../security/auth/DefaultHttpCredentialsPlugin.java | 7 ++++---
.../auth/DefaultHttpCredentialsPlugin_test.clj | 16 +++++++++++++++-
2 files changed, 19 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/storm/blob/22a81920/storm-core/src/jvm/backtype/storm/security/auth/DefaultHttpCredentialsPlugin.java
----------------------------------------------------------------------
diff --git a/storm-core/src/jvm/backtype/storm/security/auth/DefaultHttpCredentialsPlugin.java b/storm-core/src/jvm/backtype/storm/security/auth/DefaultHttpCredentialsPlugin.java
index 59c5b06..e2469e5 100644
--- a/storm-core/src/jvm/backtype/storm/security/auth/DefaultHttpCredentialsPlugin.java
+++ b/storm-core/src/jvm/backtype/storm/security/auth/DefaultHttpCredentialsPlugin.java
@@ -83,12 +83,13 @@ public class DefaultHttpCredentialsPlugin implements IHttpCredentialsPlugin {
userName = doAsUser;
}
+ Set<Principal> principals = new HashSet<Principal>();
if(userName != null) {
- Subject s = new Subject();
Principal p = new SingleUserPrincipal(userName);
- s.getPrincipals().add(p);
- context.setSubject(s);
+ principals.add(p);
}
+ Subject s = new Subject(true, principals, new HashSet(), new HashSet());
+ context.setSubject(s);
return context;
}
http://git-wip-us.apache.org/repos/asf/storm/blob/22a81920/storm-core/test/clj/backtype/storm/security/auth/DefaultHttpCredentialsPlugin_test.clj
----------------------------------------------------------------------
diff --git a/storm-core/test/clj/backtype/storm/security/auth/DefaultHttpCredentialsPlugin_test.clj b/storm-core/test/clj/backtype/storm/security/auth/DefaultHttpCredentialsPlugin_test.clj
index bf62a6b..6e214a2 100644
--- a/storm-core/test/clj/backtype/storm/security/auth/DefaultHttpCredentialsPlugin_test.clj
+++ b/storm-core/test/clj/backtype/storm/security/auth/DefaultHttpCredentialsPlugin_test.clj
@@ -30,7 +30,21 @@
req (Mockito/mock HttpServletRequest)]
(. (Mockito/when (. req getUserPrincipal))
thenReturn princ)
- (is (.equals exp-name (.getUserName handler req)))))))
+ (is (.equals exp-name (.getUserName handler req)))))
+
+ (testing "returns doAsUser from requests principal when Header has doAsUser param set"
+ (let [exp-name "Alice"
+ do-as-user-name "Bob"
+ princ (SingleUserPrincipal. exp-name)
+ req (Mockito/mock HttpServletRequest)
+ _ (. (Mockito/when (. req getUserPrincipal))
+ thenReturn princ)
+ _ (. (Mockito/when (. req getHeader "doAsUser"))
+ thenReturn do-as-user-name)
+ context (.populateContext handler (ReqContext/context) req)]
+ (is (= true (.isImpersonating context)))
+ (is (.equals exp-name (.getName (.realPrincipal context))))
+ (is (.equals do-as-user-name (.getName (.principal context))))))))
(deftest test-populate-req-context-on-null-user
(let [req (Mockito/mock HttpServletRequest)