Skip to content

Commit 0a690e8

Browse files
committed
new users added
1 parent f1dc708 commit 0a690e8

6 files changed

Lines changed: 202 additions & 88 deletions

File tree

dockerfiles/tiltaksgjennomforing-api.dockerfile

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,7 @@ COPY ./dist/tiltaksgjennomforing-api-sut.jar .
44
COPY ./dist/jacocoagent.jar .
55

66

7-
ENV AZURE_APP_WELL_KNOWN_URL="http://mock-oauth2-server:8083/aad/.well-known/openid-configuration"
8-
ENV TOKEN_X_WELL_KNOWN_URL="http://mock-oauth2-server:8083/tokenx/.well-known/openid-configuration"
9-
ENV VAULT_TOKEN="VAULT_TOKEN"
10-
ENV KAFKA_BROKERS="KAFKA_BROKERS"
11-
ENV KAFKA_TRUSTSTORE_PATH="KAFKA_TRUSTSTORE_PATH"
12-
ENV KAFKA_CREDSTORE_PASSWORD="KAFKA_CREDSTORE_PASSWORD"
13-
ENV KAFKA_KEYSTORE_PATH="KAFKA_KEYSTORE_PATH"
14-
ENV KAFKA_SCHEMA_REGISTRY="KAFKA_SCHEMA_REGISTRY"
15-
ENV KAFKA_SCHEMA_REGISTRY_USER="KAFKA_SCHEMA_REGISTRY_USER"
16-
ENV KAFKA_SCHEMA_REGISTRY_PASSWORD="KAFKA_SCHEMA_REGISTRY_PASSWORD"
17-
ENV AZURE_APP_TENANT_ID="AZURE_APP_TENANT_ID"
18-
ENV AZURE_APP_CLIENT_ID="aad"
19-
ENV AZURE_APP_CLIENT_SECRET="secret"
20-
ENV beslutter.ad.gruppe="99ea78dc-db77-44d0-b193-c5dc22f01e1d"
7+
218
#ENV TOOL="undefined"
229
#ENV RUN="0"
2310

@@ -27,4 +14,4 @@ ENTRYPOINT \
2714
# -javaagent:jacocoagent.jar=destfile=./jacoco/tiltaksgjennomforing-api__${TOOL}__${RUN}__jacoco.exec,append=false,dumponexit=true \
2815
-javaagent:jacocoagent.jar=output=tcpserver,address=*,port=6300,append=false,dumponexit=false \
2916
-jar tiltaksgjennomforing-api-sut.jar \
30-
--server.port=8080 --spring.profiles.active=dev-gcp-labs --spring.datasource.driverClassName=org.postgresql.Driver --spring.sql.init.platform=postgres --no.nav.security.jwt.issuer.aad.discoveryurl=http://mock-oauth2-server:8083/aad/.well-known/openid-configuration --no.nav.security.jwt.issuer.tokenx.discoveryurl=http://mock-oauth2-server:8083/tokenx/.well-known/openid-configuration --management.server.port=-1 --server.ssl.enabled=false --spring.datasource.url=jdbc:postgresql://db:5432/tiltaksgjennomforing --spring.datasource.username=postgres --spring.datasource.password=password --sentry.logging.enabled=false --sentry.environment=local --logging.level.root=OFF --logging.config=classpath:logback-spring.xml --logging.level.org.springframework=INFO
17+
--server.port=8080 --spring.profiles.active=dev-gcp-labs --spring.datasource.driverClassName=org.postgresql.Driver --spring.sql.init.platform=postgres --no.nav.security.jwt.issuer.aad.discoveryurl=http://mock-oauth2-server:8083/aad/.well-known/openid-configuration --no.nav.security.jwt.issuer.aad.accepted_audience=aad --no.nav.security.jwt.issuer.system.discoveryurl=http://mock-oauth2-server:8083/system/.well-known/openid-configuration --no.nav.security.jwt.issuer.system.accepted_audience=system --no.nav.security.jwt.issuer.tokenx.discoveryurl=http://mock-oauth2-server:8083/tokenx/.well-known/openid-configuration --no.nav.security.jwt.issuer.tokenx.accepted_audience=tokenx --management.server.port=-1 --server.ssl.enabled=false --spring.datasource.url=jdbc:postgresql://db:5432/tiltaksgjennomforing --spring.datasource.username=postgres --spring.datasource.password=password --sentry.logging.enabled=false --sentry.environment=local --logging.level.root=OFF --logging.config=classpath:logback-spring.xml --logging.level.org.springframework=INFO

dockerfiles/tiltaksgjennomforing-api.yaml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,31 @@ services:
99
ports:
1010
- "${HOST_PORT:-8080}:8080"
1111
- "${JACOCO_PORT:-6300}:6300"
12-
depends_on:
13-
mock-oauth2-server:
14-
condition: service_started
15-
db:
16-
condition: service_started
1712
# volumes:
1813
# default env does not work on volumes
1914
# - ${JACOCODIR}:/jacoco
2015
db:
2116
image: postgres:13.13
2217
tmpfs:
2318
- '/var/lib/postgresql/data'
19+
20+
2421
environment:
2522
POSTGRES_PASSWORD: password
2623
POSTGRES_HOST_AUTH_METHOD: trust
2724
POSTGRES_DB: tiltaksgjennomforing
25+
26+
27+
28+
2829

2930
mock-oauth2-server:
3031
image: ghcr.io/navikt/mock-oauth2-server:2.0.1
31-
ports:
32-
- "${HOST_MOCK_PORT:-8083}:8083"
33-
hostname: host.docker.internal
3432
environment:
3533
LOG_LEVEL: VERBOSE
3634
SERVER_PORT: 8083
3735
JSON_CONFIG_PATH: /app/mockoauth2.json
3836
volumes:
3937
- ../scripts/dockerize/data/additional_files/tiltaksgjennomforing-api/mockoauth2.json:/app/mockoauth2.json
38+
ports:
39+
- "8083:8083"

jdk_17_maven/em/embedded/rest/tiltaksgjennomforing-api/src/main/java/em/embedded/rest/tiltaksgjennomforing/api/EmbeddedEvoMasterController.java

Lines changed: 57 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import no.nav.security.mock.oauth2.token.RequestMapping;
77
import no.nav.security.mock.oauth2.token.RequestMappingTokenCallback;
88
import no.nav.tag.tiltaksgjennomforing.TiltaksgjennomforingApplication;
9+
import no.nav.tag.tiltaksgjennomforing.autorisasjon.TokenUtils;
910
import org.evomaster.client.java.controller.EmbeddedSutController;
1011
import org.evomaster.client.java.controller.InstrumentedSutStarter;
1112
import org.evomaster.client.java.controller.api.dto.SutInfoDto;
@@ -49,11 +50,7 @@ public class EmbeddedEvoMasterController extends EmbeddedSutController {
4950
private List<DbSpecification> dbSpecification;
5051

5152
private MockOAuth2Server oAuth2Server;
52-
private final String ISSUER_ID = "aad";
53-
private final String DEFAULT_AUDIENCE = "some-audience";
5453
private final String BESLUTTER_AD_GROUP = "99ea78dc-db77-44d0-b193-c5dc22f01e1d";
55-
private final String TOKEN_PARAM = "NAVident";
56-
private static final String NAV1 = "Q987654";
5754

5855

5956
public EmbeddedEvoMasterController() {
@@ -86,14 +83,14 @@ public String getPackagePrefixesToCover() {
8683
return "no.nav.tag.tiltaksgjennomforing.";
8784
}
8885

89-
private AuthenticationDto getAuthenticationDto(String label, String oauth2Url){
86+
private AuthenticationDto getAuthenticationDto(String label, String keyValue, String oauth2Url){
9087

9188
AuthenticationDto dto = new AuthenticationDto(label);
9289
LoginEndpointDto x = new LoginEndpointDto();
9390
dto.loginEndpointAuth = x;
9491

9592
x.externalEndpointURL = oauth2Url;
96-
x.payloadRaw = TOKEN_PARAM+"="+label+"&grant_type=client_credentials&code=foo&client_id=foo&client_secret=secret";
93+
x.payloadRaw = keyValue+"&grant_type=client_credentials&code=foo&client_id=foo&client_secret=secret";
9794
x.verb = HttpVerb.POST;
9895
x.contentType = "application/x-www-form-urlencoded";
9996
x.expectCookies = false;
@@ -109,10 +106,15 @@ private AuthenticationDto getAuthenticationDto(String label, String oauth2Url){
109106

110107
@Override
111108
public List<AuthenticationDto> getInfoForAuthentication() {
112-
// NAVident=Q987654&grant_type=client_credentials&code=foo&client_id=foo&client_secret=secret
113-
String url = oAuth2Server.baseUrl() + ISSUER_ID + "/token";
109+
String urlAad = oAuth2Server.baseUrl() + "aad/token";
110+
String urlSystem = oAuth2Server.baseUrl() + "system/token";
111+
String urlTokenX = oAuth2Server.baseUrl() + "tokenx/token";
112+
114113
return Arrays.asList(
115-
getAuthenticationDto(NAV1,url)
114+
getAuthenticationDto("aad","NAVident=Q987654", urlAad),
115+
getAuthenticationDto("system","sub=system", urlSystem),
116+
getAuthenticationDto("tokenxLevel3","pid=88888888888", urlTokenX),
117+
getAuthenticationDto("tokenxLevel4","pid=99999999999", urlTokenX)
116118
);
117119
}
118120

@@ -129,49 +131,71 @@ public SutInfoDto.OutputFormat getPreferredOutputFormat() {
129131
return SutInfoDto.OutputFormat.JAVA_JUNIT_5;
130132
}
131133

132-
private RequestMapping getRequestMapping(String id, List<String> groups, String name) {
134+
private RequestMapping getRequestMapping(String key, String value, String issuer, String subject, List<String> audience, String navIdent, String acrLevel, List<String> groups, String pid) {
133135
Map<String,Object> claims = new HashMap<>();
134-
claims.put("groups",groups);
135-
claims.put("name",name);
136-
claims.put("NAVident", id);
137-
claims.put("sub","sub");
138-
claims.put("aud",Arrays.asList("fake-aad"));
139-
claims.put("tid",ISSUER_ID);
140-
claims.put("azp",id);
141-
claims.put("acr","Level4");
142-
claims.put("nonce","myNonce");
143-
144-
RequestMapping rm = new RequestMapping("NAVident",id, claims, JOSEObjectType.JWT.getType());
136+
claims.put("groups", groups);
137+
claims.put("NAVident", navIdent);
138+
claims.put("sub", subject);
139+
claims.put("aud", audience);
140+
claims.put("roles", Arrays.asList("access_as_application"));
141+
claims.put("pid", pid);
142+
claims.put("tid", issuer);
143+
claims.put("azp", navIdent);
144+
claims.put("acr", acrLevel);
145+
claims.put("ver", "1.0");
146+
claims.put("nonce", "myNonce");
147+
148+
RequestMapping rm = new RequestMapping(key, value, claims, JOSEObjectType.JWT.getType());
145149

146150
return rm;
147151
}
148152

149153
private OAuth2Config getOAuth2Config(){
150154

151155
List<RequestMapping> mappings = Arrays.asList(
152-
getRequestMapping(NAV1, Arrays.asList(BESLUTTER_AD_GROUP),"Mock McMockface")
156+
getRequestMapping("NAVident", "Q987654", "aad","blablabla", Arrays.asList("aad"), "Q987654", "Level4", Arrays.asList(BESLUTTER_AD_GROUP), "aad")
157+
);
158+
159+
List<RequestMapping> mappingsSystem = Arrays.asList(
160+
getRequestMapping("sub", "system", "system","system", Arrays.asList("system"), null, null, null, "system")
161+
);
162+
163+
List<RequestMapping> mappingsTokenx = Arrays.asList(
164+
getRequestMapping("pid", "88888888888", "tokenx","tokenx", Arrays.asList("tokenx"), null, "Level3", null, "88888888888"),
165+
getRequestMapping("pid", "99999999999", "tokenx","tokenx", Arrays.asList("tokenx"), null, "Level4", null, "99999999999")
153166
);
154167

155168
RequestMappingTokenCallback callback = new RequestMappingTokenCallback(
156-
ISSUER_ID,
169+
"aad",
157170
mappings,
158171
360000
159172
);
173+
RequestMappingTokenCallback callbackSystem = new RequestMappingTokenCallback(
174+
"system",
175+
mappingsSystem,
176+
360000
177+
);
178+
179+
RequestMappingTokenCallback callbackTokenx = new RequestMappingTokenCallback(
180+
"tokenx",
181+
mappingsTokenx,
182+
360000
183+
);
160184

161185
Set<RequestMappingTokenCallback> callbacks = Set.of(
162-
callback
186+
callback,
187+
callbackSystem,
188+
callbackTokenx
163189
);
164190

165-
OAuth2Config config = new OAuth2Config(
191+
return new OAuth2Config(
166192
true,
167193
null,
168194
null,
169195
false,
170196
new no.nav.security.mock.oauth2.token.OAuth2TokenProvider(),
171197
callbacks
172198
);
173-
174-
return config;
175199
}
176200

177201
@Override
@@ -182,7 +206,8 @@ public String startSut() {
182206

183207
oAuth2Server = new MockOAuth2Server(getOAuth2Config());
184208
oAuth2Server.start(8081); //ephemeral gives issues in generated tests
185-
String wellKnownUrl = oAuth2Server.wellKnownUrl(ISSUER_ID).toString();
209+
String wellKnownUrl = oAuth2Server.wellKnownUrl("aad").toString();
210+
String wellKnownUrlSystem = oAuth2Server.wellKnownUrl("system").toString();
186211
String wellKnownUrlTokenX = oAuth2Server.wellKnownUrl("tokenx").toString();
187212

188213
//TODO should go through all the environment variables in application properties
@@ -210,7 +235,11 @@ public String startSut() {
210235
"--spring.datasource.driverClassName=org.postgresql.Driver",
211236
"--spring.sql.init.platform=postgres",
212237
"--no.nav.security.jwt.issuer.aad.discoveryurl=" + wellKnownUrl,
238+
"--no.nav.security.jwt.issuer.aad.accepted_audience=aad",
239+
"--no.nav.security.jwt.issuer.system.discoveryurl=" + wellKnownUrlSystem,
240+
"--no.nav.security.jwt.issuer.system.accepted_audience=system",
213241
"--no.nav.security.jwt.issuer.tokenx.discoveryurl=" + wellKnownUrlTokenX,
242+
"--no.nav.security.jwt.issuer.tokenx.accepted_audience=tokenx",
214243
"--management.server.port=-1",
215244
"--server.ssl.enabled=false",
216245
"--spring.datasource.url=" + postgresURL,

0 commit comments

Comments
 (0)