Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
I
Indexer
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
System
Indexer
Commits
44b736d9
Commit
44b736d9
authored
5 years ago
by
Wyatt Nielsen
Browse files
Options
Downloads
Patches
Plain Diff
Fix duplicate AuthorizationService.java and missing entitlements bean from is-core
parent
72d9453a
No related branches found
No related tags found
1 merge request
!6
Trusted ibm
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
indexer-core/src/test/java/org/opengroup/osdu/indexer/auth/AuthorizationServiceEntitlementsTest.java
+0
-153
0 additions, 153 deletions
...du/indexer/auth/AuthorizationServiceEntitlementsTest.java
with
0 additions
and
153 deletions
indexer-core/src/test/java/org/opengroup/osdu/indexer/auth/AuthorizationServiceEntitlementsTest.java
deleted
100644 → 0
+
0
−
153
View file @
72d9453a
// Copyright 2017-2019, Schlumberger
//
// 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.indexer.auth
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.mockito.InjectMocks
;
import
org.mockito.Mock
;
import
org.opengroup.osdu.core.common.model.entitlements.EntitlementsException
;
import
org.opengroup.osdu.core.common.service.entitlements.IEntitlementsFactory
;
import
org.opengroup.osdu.core.common.service.entitlements.IEntitlementsService
;
import
org.opengroup.osdu.core.common.model.entitlements.GroupInfo
;
import
org.opengroup.osdu.core.common.model.entitlements.Groups
;
import
org.opengroup.osdu.core.common.model.http.DpsHeaders
;
import
org.opengroup.osdu.core.common.model.http.AppException
;
import
org.opengroup.osdu.core.common.service.http.HttpResponse
;
import
org.opengroup.osdu.core.common.model.entitlements.AuthorizationResponse
;
import
org.opengroup.osdu.core.common.service.logging.JaxRsDpsLog
;
import
org.springframework.test.context.junit4.SpringRunner
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
fail
;
import
static
org
.
mockito
.
Matchers
.
any
;
import
static
org
.
mockito
.
Mockito
.
when
;
@RunWith
(
SpringRunner
.
class
)
public
class
AuthorizationServiceEntitlementsTest
{
@Mock
private
IEntitlementsFactory
entitlementsFactory
;
@Mock
private
IEntitlementsService
service
;
@Mock
private
JaxRsDpsLog
log
;
@InjectMocks
private
AuthorizationServiceEntitlements
sut
;
@Before
public
void
setup
()
{
when
(
entitlementsFactory
.
create
(
any
())).
thenReturn
(
service
);
}
@Test
public
void
should_returnUser_when_ussrHasPermission
()
throws
EntitlementsException
{
sut
=
createSut
(
"service.search.user"
);
AuthorizationResponse
result
=
sut
.
authorizeAny
(
DpsHeaders
.
createFromMap
(
new
HashMap
<>()),
"service.search.user"
);
assertEquals
(
"iamtester@dps.com"
,
result
.
getUser
());
}
@Test
public
void
should_returnUser_when_ussrHasAnyPermission
()
throws
EntitlementsException
{
sut
=
createSut
(
"service.search.user"
);
AuthorizationResponse
result
=
sut
.
authorizeAny
(
DpsHeaders
.
createFromMap
(
new
HashMap
<>()),
"service.search.user"
,
"service.search.owner"
);
assertEquals
(
"iamtester@dps.com"
,
result
.
getUser
());
}
@Test
public
void
should_throwUnauthorized_when_userDoesNotHaveRequiredPermission
()
throws
EntitlementsException
{
sut
=
createSut
(
"service.search.user"
);
try
{
sut
.
authorizeAny
(
DpsHeaders
.
createFromMap
(
new
HashMap
<>()),
"service.search.owner"
);
fail
(
"expected exception"
);
}
catch
(
AppException
ex
)
{
assertEquals
(
401
,
ex
.
getError
().
getCode
());
}
}
@Test
public
void
should_throwUnauthorized_when_userDoesNotBelongToAnyGroup
()
throws
EntitlementsException
{
sut
=
createSut
(
"service.search.user"
);
HttpResponse
response
=
new
HttpResponse
();
response
.
setResponseCode
(
401
);
when
(
service
.
getGroups
()).
thenThrow
(
new
EntitlementsException
(
""
,
response
));
try
{
sut
.
authorizeAny
(
DpsHeaders
.
createFromMap
(
new
HashMap
<>()),
"service.search.owner"
);
fail
(
"expected exception"
);
}
catch
(
AppException
ex
)
{
assertEquals
(
401
,
ex
.
getError
().
getCode
());
}
}
@Test
public
void
should_throwServerError_when_getGroupsThrowsServerError
()
throws
EntitlementsException
{
sut
=
createSut
(
"service.search.user"
);
HttpResponse
response
=
new
HttpResponse
();
response
.
setResponseCode
(
500
);
when
(
service
.
getGroups
()).
thenThrow
(
new
EntitlementsException
(
""
,
response
));
try
{
sut
.
authorizeAny
(
DpsHeaders
.
createFromMap
(
new
HashMap
<>()),
"service.search.owner"
);
fail
(
"expected exception"
);
}
catch
(
AppException
ex
)
{
assertEquals
(
500
,
ex
.
getError
().
getCode
());
}
}
@Test
public
void
should_throw403AppError_when_getGroupsThrows400EntitlementsError
()
throws
EntitlementsException
{
sut
=
createSut
(
"service.search.user"
);
HttpResponse
response
=
new
HttpResponse
();
response
.
setResponseCode
(
403
);
when
(
service
.
getGroups
()).
thenThrow
(
new
EntitlementsException
(
""
,
response
));
try
{
sut
.
authorizeAny
(
DpsHeaders
.
createFromMap
(
new
HashMap
<>()),
"service.search.owner"
);
fail
(
"expected exception"
);
}
catch
(
AppException
ex
)
{
assertEquals
(
403
,
ex
.
getError
().
getCode
());
}
}
private
AuthorizationServiceEntitlements
createSut
(
String
...
roles
)
throws
EntitlementsException
{
List
<
GroupInfo
>
groupInfos
=
new
ArrayList
<>();
for
(
String
s
:
roles
)
{
GroupInfo
group
=
new
GroupInfo
();
group
.
setName
(
s
);
groupInfos
.
add
(
group
);
}
Groups
output
=
new
Groups
();
output
.
setMemberEmail
(
"iamtester@dps.com"
);
output
.
setGroups
(
groupInfos
);
when
(
service
.
getGroups
()).
thenReturn
(
output
);
return
sut
;
}
}
This diff is collapsed.
Click to expand it.
Gokul Nagare
@gokul_nagare
mentioned in commit
d5255c23
·
4 years ago
mentioned in commit
d5255c23
mentioned in commit d5255c238ba67a6989a5a7dbc26c03b56b0b4f9e
Toggle commit list
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