Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
ac
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
OATS-CADC
ac
Commits
340bcb14
Commit
340bcb14
authored
9 years ago
by
Brian Major
Browse files
Options
Downloads
Plain Diff
Merge branch 'ac2' of
ssh://gimli2.cadc.dao.nrc.ca/srv/cadc/git/wopencadc
into ac2
parents
49421dd6
c2829de2
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
projects/cadcAccessControl/test/src/ca/nrc/cadc/ac/client/UserClientTest.java
+70
-1
70 additions, 1 deletion
...ontrol/test/src/ca/nrc/cadc/ac/client/UserClientTest.java
with
70 additions
and
1 deletion
projects/cadcAccessControl/test/src/ca/nrc/cadc/ac/client/UserClientTest.java
+
70
−
1
View file @
340bcb14
...
@@ -69,9 +69,22 @@
...
@@ -69,9 +69,22 @@
package
ca.nrc.cadc.ac.client
;
package
ca.nrc.cadc.ac.client
;
import
java.net.MalformedURLException
;
import
java.net.URI
;
import
java.net.URISyntaxException
;
import
java.net.URL
;
import
java.security.Principal
;
import
javax.management.remote.JMXPrincipal
;
import
javax.security.auth.Subject
;
import
org.apache.log4j.Level
;
import
org.apache.log4j.Level
;
import
org.apache.log4j.Logger
;
import
org.apache.log4j.Logger
;
import
ca.nrc.cadc.ac.client.UserClient
;
import
ca.nrc.cadc.ac.AC
;
import
ca.nrc.cadc.auth.HttpPrincipal
;
import
ca.nrc.cadc.auth.NumericPrincipal
;
import
ca.nrc.cadc.reg.client.RegistryClient
;
import
ca.nrc.cadc.util.Log4jInit
;
import
ca.nrc.cadc.util.Log4jInit
;
import
org.junit.Assert
;
import
org.junit.Assert
;
...
@@ -123,4 +136,60 @@ public class UserClientTest
...
@@ -123,4 +136,60 @@ public class UserClientTest
Assert
.
fail
(
"Unexpected exception: "
+
t
.
getMessage
());
Assert
.
fail
(
"Unexpected exception: "
+
t
.
getMessage
());
}
}
}
}
@Test
public
void
testSubjectWithNoPrincipal
()
throws
URISyntaxException
,
MalformedURLException
{
// test subject augmentation given a subject with no principal
Subject
subject
=
new
Subject
();
this
.
createUserClient
().
augmentSubject
(
subject
);
Assert
.
assertEquals
(
"Should have no principal."
,
0
,
subject
.
getPrincipals
().
size
());
}
@Test
public
void
testSubjectWithMultiplePrincipal
()
throws
URISyntaxException
,
MalformedURLException
{
try
{
// test subject augmentation given a subject with more than one principal
Subject
subject
=
new
Subject
();
subject
.
getPrincipals
().
add
(
new
NumericPrincipal
(
4
));
subject
.
getPrincipals
().
add
(
new
HttpPrincipal
(
"cadcauthtest1"
));
this
.
createUserClient
().
augmentSubject
(
subject
);
Assert
.
fail
(
"Expecting an IllegalArgumentException."
);
}
catch
(
IllegalArgumentException
e
)
{
String
expected
=
"Subject has more than one principal."
;
Assert
.
assertEquals
(
expected
,
e
.
getMessage
());
}
}
@Test
public
void
testSubjectWithUnsupportedPrincipal
()
throws
URISyntaxException
,
MalformedURLException
{
Principal
principal
=
new
JMXPrincipal
(
"APIName"
);
try
{
// test subject augmentation given a subject with more than one principal
Subject
subject
=
new
Subject
();
subject
.
getPrincipals
().
add
(
principal
);
this
.
createUserClient
().
augmentSubject
(
subject
);
Assert
.
fail
(
"Expecting an IllegalArgumentException."
);
}
catch
(
IllegalArgumentException
e
)
{
String
expected
=
"Subject has unsupported principal "
+
principal
.
getName
();
Assert
.
assertEquals
(
expected
,
e
.
getMessage
());
}
}
protected
UserClient
createUserClient
()
throws
URISyntaxException
,
MalformedURLException
{
RegistryClient
regClient
=
new
RegistryClient
();
URI
serviceURI
=
new
URI
(
AC
.
GMS_SERVICE_URI
);
URL
baseURL
=
regClient
.
getServiceURL
(
serviceURI
,
"https"
);
return
new
UserClient
(
baseURL
.
toString
());
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment