Search in sources :

Example 1 with FakeElegCredentials

use of se.inera.intyg.webcert.web.auth.eleg.FakeElegCredentials in project webcert by sklintyg.

the class UtkastModuleApiControllerIT method testServerSigneraUtkastMedGrp.

@Test
public void testServerSigneraUtkastMedGrp() throws IOException {
    FakeElegCredentials fakeElegCredentials = new FakeElegCredentials();
    fakeElegCredentials.setPersonId(TOLVAN_PERSON_ID);
    fakeElegCredentials.setPrivatLakare(true);
    RestAssured.sessionId = getAuthSession(fakeElegCredentials);
    Intyg intyg = createIntyg();
    // var knownSignStatuses = {'BEARBETAR':'', 'VANTA_SIGN':'', 'NO_CLIENT':'', 'SIGNERAD':'', 'OKAND': ''};
    // Påbörja signering
    Response responseTicket = given().cookie("ROUTEID", BaseRestIntegrationTest.routeId).contentType(ContentType.JSON).expect().statusCode(200).when().post(MODULEAPI_UTKAST_BASE + "/" + intyg.getIntygsTyp() + "/" + intyg.getId() + "/" + intyg.getVersion() + "/grp/signeraserver").then().body(matchesJsonSchemaInClasspath("jsonschema/webcert-signatur-response-schema.json")).body("status", equalTo("BEARBETAR")).extract().response();
    // Hämta ut biljett-id från svaret
    JsonPath model = new JsonPath(responseTicket.body().asString());
    String biljettId = model.getString("id");
    // biljettId är inte samma sak som orderRef.
    // Hämta ut orderRef först
    Response responseOrderRef = given().cookie("ROUTEID", BaseRestIntegrationTest.routeId).contentType(ContentType.TEXT).expect().statusCode(200).when().get(GRPAPI_STUBBE_BASE + "/orderref/" + biljettId).then().extract().response();
    String orderRef = responseOrderRef.body().asString();
    // Ändra GRP-status till USER_SIGN och kontrollera
    given().cookie("ROUTEID", BaseRestIntegrationTest.routeId).contentType(ContentType.JSON).body(createGrpSignatureStatus(orderRef, ProgressStatusType.USER_SIGN)).expect().statusCode(200).when().put(GRPAPI_STUBBE_BASE + "/status");
    // Simulera väntetid vid pollning mot riktig GPR-tjänst
    sleep();
    given().cookie("ROUTEID", BaseRestIntegrationTest.routeId).contentType(ContentType.JSON).expect().statusCode(200).when().get(MODULEAPI_UTKAST_BASE + "/" + intyg.getIntygsTyp() + "/" + biljettId + "/signeringsstatus").then().body(matchesJsonSchemaInClasspath("jsonschema/webcert-signatur-response-schema.json")).body("status", equalTo("VANTA_SIGN"));
    // Ändra GRP-status till COMPLETE och kontrollera
    given().cookie("ROUTEID", BaseRestIntegrationTest.routeId).contentType(ContentType.JSON).body(createGrpSignatureStatus(orderRef, ProgressStatusType.COMPLETE)).expect().statusCode(200).when().put(GRPAPI_STUBBE_BASE + "/status");
    // Simulera väntetid vid pollning mot riktig GPR-tjänst
    sleep();
    given().cookie("ROUTEID", BaseRestIntegrationTest.routeId).contentType(ContentType.JSON).expect().statusCode(200).when().get(MODULEAPI_UTKAST_BASE + "/" + intyg.getIntygsTyp() + "/" + biljettId + "/signeringsstatus").then().body(matchesJsonSchemaInClasspath("jsonschema/webcert-signatur-response-schema.json")).body("status", equalTo("SIGNERAD"));
}
Also used : Response(com.jayway.restassured.response.Response) FakeElegCredentials(se.inera.intyg.webcert.web.auth.eleg.FakeElegCredentials) Matchers.isEmptyString(org.hamcrest.Matchers.isEmptyString) JsonPath(com.jayway.restassured.path.json.JsonPath) Test(org.junit.Test) BaseRestIntegrationTest(se.inera.intyg.webcert.web.web.controller.integrationtest.BaseRestIntegrationTest)

Example 2 with FakeElegCredentials

use of se.inera.intyg.webcert.web.auth.eleg.FakeElegCredentials in project webcert by sklintyg.

the class FakeAuthenticationFilter method performFakeElegAuthentication.

private Authentication performFakeElegAuthentication(String json) {
    try {
        FakeElegCredentials fakeElegCredentials = new ObjectMapper().readValue(json, FakeElegCredentials.class);
        LOG.info("Detected fake credentials " + fakeElegCredentials);
        return getAuthenticationManager().authenticate(new FakeElegAuthenticationToken(fakeElegCredentials));
    } catch (IOException e) {
        String message = "Failed to parse JSON for fake E-leg: " + json;
        LOG.error(message, e);
        throw new RuntimeException(message, e);
    }
}
Also used : FakeElegAuthenticationToken(se.inera.intyg.webcert.web.auth.eleg.FakeElegAuthenticationToken) FakeElegCredentials(se.inera.intyg.webcert.web.auth.eleg.FakeElegCredentials) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 3 with FakeElegCredentials

use of se.inera.intyg.webcert.web.auth.eleg.FakeElegCredentials in project webcert by sklintyg.

the class CertificateIntegrationControllerIT method testRedirectWithTypeFailsWithInvalidRole.

@Test
public void testRedirectWithTypeFailsWithInvalidRole() {
    FakeElegCredentials fakeElegCredentials = new FakeElegCredentials();
    fakeElegCredentials.setPersonId("19121212-1212");
    fakeElegCredentials.setPrivatLakare(true);
    RestAssured.sessionId = getAuthSession(fakeElegCredentials);
    given().cookie("ROUTEID", BaseRestIntegrationTest.routeId).redirects().follow(false).and().pathParams("intygsId", DEFAULT_INTYGSID, "intygsTyp", INTYGSTYP).expect().statusCode(HttpServletResponse.SC_TEMPORARY_REDIRECT).when().get("webcert/web/user/basic-certificate/{intygsTyp}/{intygsId}/questions").then().header(HttpHeaders.LOCATION, endsWith("/error.jsp?reason=auth-exception"));
}
Also used : FakeElegCredentials(se.inera.intyg.webcert.web.auth.eleg.FakeElegCredentials) Test(org.junit.Test) BaseRestIntegrationTest(se.inera.intyg.webcert.web.web.controller.integrationtest.BaseRestIntegrationTest)

Example 4 with FakeElegCredentials

use of se.inera.intyg.webcert.web.auth.eleg.FakeElegCredentials in project webcert by sklintyg.

the class CertificateIntegrationControllerIT method testRedirectFailsWithInvalidRole.

@Test
public void testRedirectFailsWithInvalidRole() {
    FakeElegCredentials fakeElegCredentials = new FakeElegCredentials();
    fakeElegCredentials.setPersonId("19121212-1212");
    fakeElegCredentials.setPrivatLakare(true);
    RestAssured.sessionId = getAuthSession(fakeElegCredentials);
    given().cookie("ROUTEID", BaseRestIntegrationTest.routeId).redirects().follow(false).and().pathParam("intygsId", DEFAULT_INTYGSID).expect().statusCode(HttpServletResponse.SC_TEMPORARY_REDIRECT).when().get("webcert/web/user/basic-certificate/{intygsId}/questions").then().header(HttpHeaders.LOCATION, endsWith("/error.jsp?reason=auth-exception"));
}
Also used : FakeElegCredentials(se.inera.intyg.webcert.web.auth.eleg.FakeElegCredentials) Test(org.junit.Test) BaseRestIntegrationTest(se.inera.intyg.webcert.web.web.controller.integrationtest.BaseRestIntegrationTest)

Aggregations

FakeElegCredentials (se.inera.intyg.webcert.web.auth.eleg.FakeElegCredentials)4 Test (org.junit.Test)3 BaseRestIntegrationTest (se.inera.intyg.webcert.web.web.controller.integrationtest.BaseRestIntegrationTest)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 JsonPath (com.jayway.restassured.path.json.JsonPath)1 Response (com.jayway.restassured.response.Response)1 IOException (java.io.IOException)1 Matchers.isEmptyString (org.hamcrest.Matchers.isEmptyString)1 FakeElegAuthenticationToken (se.inera.intyg.webcert.web.auth.eleg.FakeElegAuthenticationToken)1