Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
L
Legal
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
OSDU
OSDU Data Platform
Security and Compliance
Legal
Commits
03bab0a9
Commit
03bab0a9
authored
4 years ago
by
Aalekh Jain
Browse files
Options
Downloads
Patches
Plain Diff
Added UT for `whoami` method in `WhoamiController.java`
parent
f98e8ca6
No related branches found
No related tags found
1 merge request
!61
Improve code coverage
Pipeline
#9767
failed
4 years ago
Stage: review
Changes
1
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
provider/legal-azure/src/test/java/org/opengroup/osdu/legal/azure/security/WhoamiControllerTest.java
+68
-1
68 additions, 1 deletion
...group/osdu/legal/azure/security/WhoamiControllerTest.java
with
68 additions
and
1 deletion
provider/legal-azure/src/test/java/org/opengroup/osdu/legal/azure/security/WhoamiControllerTest.java
+
68
−
1
View file @
03bab0a9
package
org.opengroup.osdu.legal.azure.security
;
public
class
WhoamiControllerTest
{
// Copyright © Microsoft Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package
org.opengroup.osdu.legal.azure.security
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.mockito.InjectMocks
;
import
org.mockito.junit.MockitoJUnitRunner
;
import
org.springframework.security.core.Authentication
;
import
org.springframework.security.core.context.SecurityContext
;
import
java.util.*
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
mockito
.
Mockito
.*;
@RunWith
(
MockitoJUnitRunner
.
class
)
public
class
WhoamiControllerTest
{
private
static
final
String
userName
=
"username"
;
private
static
final
String
roles
=
"roles"
;
private
static
final
String
details
=
"details"
;
@InjectMocks
private
WhoamiController
sut
;
private
class
DummyPrincipal
{
@Override
public
String
toString
()
{
return
details
;
}
}
public
class
DummyAuthority
extends
ArrayList
{
@Override
public
String
toString
()
{
return
roles
;
}
}
@Before
public
void
init
()
{
Authentication
auth
=
mock
(
Authentication
.
class
);
SecurityContext
securityContext
=
mock
(
SecurityContext
.
class
);
doReturn
(
auth
).
when
(
securityContext
).
getAuthentication
();
doReturn
(
userName
).
when
(
auth
).
getName
();
doReturn
(
new
DummyAuthority
()).
when
(
auth
).
getAuthorities
();
doReturn
(
new
DummyPrincipal
()).
when
(
auth
).
getPrincipal
();
sut
=
new
WhoamiController
(
securityContext
);
}
@Test
public
void
testWhoamiResponse
()
{
String
response
=
sut
.
whoami
();
assertEquals
(
"user: username<BR>roles: roles<BR>details: details<BR>"
,
response
);
}
}
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