Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
EGA
ega-data-api
Commits
481437c1
Unverified
Commit
481437c1
authored
Apr 21, 2021
by
Anand Mohan
Committed by
GitHub
Apr 21, 2021
Browse files
Merge pull request #199 from EGA-archive/bugfix/EE-1919
Ignore duplicates when producing map using streams
parents
efab47ea
2c74229a
Pipeline
#153717
passed with stages
in 6 minutes and 30 seconds
Changes
3
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
121 additions
and
24 deletions
+121
-24
.gitlab-ci.yml
.gitlab-ci.yml
+0
-22
ega-data-api-commons/src/main/java/eu/elixir/ega/ebi/commons/config/MyAccessTokenConverter.java
...elixir/ega/ebi/commons/config/MyAccessTokenConverter.java
+2
-2
ega-data-api-commons/src/test/java/eu/elixir/ega/ebi/commons/config/MyAccessTokenConverterTest.java
...ir/ega/ebi/commons/config/MyAccessTokenConverterTest.java
+119
-0
No files found.
.gitlab-ci.yml
View file @
481437c1
...
...
@@ -16,7 +16,6 @@ services:
## List of jobs:
stages
:
-
unitTest
-
integrationTest
-
imageBuild
# Cache downloaded dependencies and plugins between builds.
...
...
@@ -35,27 +34,6 @@ unitTest:
script
:
-
mvn test
integrationTest
:
stage
:
integrationTest
before_script
:
-
mvn install -DskipTests=true -P production -Dmaven.javadoc.skip=true -B -V -DskipDockerPush
# - sudo service postgresql stop
-
mkdir -p /usr/local/share/ca-certificates/
-
cp extras/certificate/rootCA.pem /usr/local/share/ca-certificates/CA.crt
-
chmod 644 /usr/local/share/ca-certificates/CA.crt
-
update-ca-certificates
-
docker build -t ega-data-api/ega-dataedge --file Dockerfile.dataedge .
-
docker build -t ega-data-api/ega-res --file Dockerfile.res .
-
docker build -t ega-data-api/ega-keyserver --file Dockerfile.keyserver .
-
docker build -t ega-data-api/ega-filedatabase --file Dockerfile.filedatabase .
-
docker build -t ega-data-api/ega-postgres --file extras/postgresdb/Dockerfile .
-
cd extras && source ./variables.sh
-
docker-compose up -d
-
sleep
90
-
cd ../ega-data-api-it
script
:
-
mvn test "-Dkey.url=https://dataedge" "-Dfile.url=https://dataedge" "-Dres.url=https://dataedge" "-Ddataedge.url=https://dataedge"
imageBuild
:
stage
:
imageBuild
script
:
...
...
ega-data-api-commons/src/main/java/eu/elixir/ega/ebi/commons/config/MyAccessTokenConverter.java
View file @
481437c1
...
...
@@ -238,7 +238,7 @@ public class MyAccessTokenConverter implements AccessTokenConverter {
.
orElse
(
null
));
}
pr
ivate
Map
<
String
,
List
<
String
>>
getDatasetFileMap
(
final
List
<
String
>
ga4ghDatasets
)
{
pr
otected
Map
<
String
,
List
<
String
>>
getDatasetFileMap
(
final
List
<
String
>
ga4ghDatasets
)
{
return
ga4ghDatasets
.
parallelStream
()
.
map
(
jwtService:
:
parse
)
...
...
@@ -249,7 +249,7 @@ public class MyAccessTokenConverter implements AccessTokenConverter {
.
map
(
this
::
getDatasetId
)
.
filter
(
Optional:
:
isPresent
)
.
map
(
Optional:
:
get
)
.
collect
(
toMap
(
datasetId
->
datasetId
,
fileDatasetService:
:
getFileIds
));
.
collect
(
toMap
(
datasetId
->
datasetId
,
fileDatasetService:
:
getFileIds
,
(
d1
,
d2
)
->
d2
));
}
private
boolean
isValidToken
(
final
SignedJWT
signedJWT
)
{
...
...
ega-data-api-commons/src/test/java/eu/elixir/ega/ebi/commons/config/MyAccessTokenConverterTest.java
0 → 100644
View file @
481437c1
package
eu.elixir.ega.ebi.commons.config
;
import
static
java
.
lang
.
System
.
currentTimeMillis
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
mockito
.
Matchers
.
any
;
import
static
org
.
mockito
.
Matchers
.
anyString
;
import
static
org
.
mockito
.
Mockito
.
when
;
import
java.io.IOException
;
import
java.net.URI
;
import
java.net.URISyntaxException
;
import
java.text.ParseException
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Optional
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.boot.test.mock.mockito.MockBean
;
import
org.springframework.test.context.junit4.SpringRunner
;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
com.fasterxml.jackson.databind.JsonNode
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.nimbusds.jose.JOSEObjectType
;
import
com.nimbusds.jose.JWSAlgorithm
;
import
com.nimbusds.jose.JWSHeader
;
import
com.nimbusds.jwt.JWTClaimsSet
;
import
com.nimbusds.jwt.SignedJWT
;
import
eu.elixir.ega.ebi.commons.shared.service.FileDatasetService
;
import
eu.elixir.ega.ebi.commons.shared.service.Ga4ghService
;
import
eu.elixir.ega.ebi.commons.shared.service.JWTService
;
import
eu.elixir.ega.ebi.commons.shared.service.UserDetailsService
;
@RunWith
(
SpringRunner
.
class
)
public
class
MyAccessTokenConverterTest
{
private
MyAccessTokenConverter
accessTokenConverter
;
@MockBean
private
JWTService
jwtService
;
@MockBean
private
Ga4ghService
ga4ghService
;
@MockBean
private
FileDatasetService
fileDatasetService
;
@MockBean
private
UserDetailsService
userDetailsService
;
private
final
String
dataset1
=
"EGAD00001"
;
private
final
String
dataset2
=
"EGAD00002"
;
@Before
public
void
before
()
{
accessTokenConverter
=
new
MyAccessTokenConverter
(
jwtService
,
ga4ghService
,
fileDatasetService
,
userDetailsService
);
}
@Test
public
void
getDatasetFileMap_whenPassDuplicateDatasets_thenReturnWithoutDuplicates
()
throws
JsonProcessingException
,
IOException
,
ParseException
,
URISyntaxException
{
commonMock
();
Map
<
String
,
List
<
String
>>
userDatasets
=
accessTokenConverter
.
getDatasetFileMap
(
get3Ga4GhDatasets
());
assertEquals
(
2
,
userDatasets
.
size
());
assertTrue
(
userDatasets
.
containsKey
(
dataset1
));
assertTrue
(
userDatasets
.
containsKey
(
dataset2
));
}
@Test
public
void
getDatasetFileMap_whenPassNoDatasets_thenReturnZeroDatasets
()
throws
JsonProcessingException
,
IOException
,
ParseException
,
URISyntaxException
{
commonMock
();
Map
<
String
,
List
<
String
>>
userDatasets
=
accessTokenConverter
.
getDatasetFileMap
(
new
ArrayList
<>());
assertEquals
(
0
,
userDatasets
.
size
());
}
private
List
<
String
>
get3Ga4GhDatasets
()
{
List
<
String
>
ga4ghDatasets
=
new
ArrayList
<>();
ga4ghDatasets
.
add
(
"header1."
+
dataset1
+
".signature1"
);
ga4ghDatasets
.
add
(
"header2."
+
dataset2
+
".signature2"
);
ga4ghDatasets
.
add
(
"header3."
+
dataset2
+
".signature3"
);
return
ga4ghDatasets
;
}
private
SignedJWT
getSignedJWT
(
String
dataset
)
throws
JsonProcessingException
,
IOException
,
ParseException
,
URISyntaxException
{
ObjectMapper
mapper
=
new
ObjectMapper
();
String
PassportVisaObjectJson
=
"{ \"type\":\"ControlledAccessGrants\", \"value\":\""
+
dataset
+
"\" }"
;
String
json
=
"{ \"exp\":"
+
(
currentTimeMillis
()
+
9000
)
+
" , \"ga4gh_visa_v1\":"
+
PassportVisaObjectJson
+
" }"
;
JsonNode
node
=
mapper
.
readTree
(
json
);
final
JWTClaimsSet
jwtClaimsSet
=
JWTClaimsSet
.
parse
(
node
.
toString
());
return
new
SignedJWT
(
getJWSHeader
(),
jwtClaimsSet
);
}
private
JWSHeader
getJWSHeader
()
throws
URISyntaxException
{
return
new
JWSHeader
.
Builder
(
JWSAlgorithm
.
parse
(
"RS256"
))
.
keyID
(
"test"
)
.
type
(
JOSEObjectType
.
JWT
)
.
jwkURL
(
new
URI
(
"http://example.com/"
))
.
build
();
}
private
void
commonMock
()
throws
IOException
,
ParseException
,
URISyntaxException
{
when
(
jwtService
.
parse
(
get3Ga4GhDatasets
().
get
(
0
))).
thenReturn
(
Optional
.
of
(
getSignedJWT
(
dataset1
)));
when
(
jwtService
.
parse
(
get3Ga4GhDatasets
().
get
(
1
))).
thenReturn
(
Optional
.
of
(
getSignedJWT
(
dataset2
)));
when
(
jwtService
.
parse
(
get3Ga4GhDatasets
().
get
(
2
))).
thenReturn
(
Optional
.
of
(
getSignedJWT
(
dataset2
)));
when
(
jwtService
.
isValidSignature
(
any
())).
thenReturn
(
true
);
when
(
fileDatasetService
.
getFileIds
(
anyString
())).
thenReturn
(
new
ArrayList
<>());
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment