Skip to content

Commit d56eb8a

Browse files
committed
Integrations added
1 parent 38c2710 commit d56eb8a

File tree

3 files changed

+148
-0
lines changed

3 files changed

+148
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Copyright (c) 2023-2024 Tracehub.git
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to read
6+
* the Software only. Permissions is hereby NOT GRANTED to use, copy, modify,
7+
* merge, publish, distribute, sublicense, and/or sell copies of the Software.
8+
*
9+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
10+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
11+
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
12+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
13+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
14+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
15+
* SOFTWARE.
16+
*/
17+
18+
package it;
19+
20+
import com.jcabi.http.mock.MkContainer;
21+
import com.jcabi.http.mock.MkGrizzlyContainer;
22+
import java.io.IOException;
23+
import org.junit.jupiter.api.AfterAll;
24+
import org.junit.jupiter.api.BeforeAll;
25+
import org.springframework.test.annotation.DirtiesContext;
26+
27+
/**
28+
* Web Server Integration Suite.
29+
*
30+
* @since 0.0.0
31+
*/
32+
@DirtiesContext
33+
@SuppressWarnings({
34+
"JTCOP.RuleCorrectTestName",
35+
"JTCOP.RuleAllTestsHaveProductionClass",
36+
"PMD.ProhibitPublicStaticMethods"
37+
})
38+
public interface ServerIntegration {
39+
40+
/**
41+
* Web Server Container.
42+
*/
43+
MkContainer SERVER = new MkGrizzlyContainer();
44+
45+
/**
46+
* Start container.
47+
*
48+
* @throws IOException If fails
49+
*/
50+
@BeforeAll
51+
static void start() throws IOException {
52+
ServerIntegration.SERVER.start();
53+
}
54+
55+
/**
56+
* Stop container.
57+
*/
58+
@AfterAll
59+
static void stop() {
60+
ServerIntegration.SERVER.stop();
61+
}
62+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Copyright (c) 2023-2024 Tracehub.git
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to read
6+
* the Software only. Permissions is hereby NOT GRANTED to use, copy, modify,
7+
* merge, publish, distribute, sublicense, and/or sell copies of the Software.
8+
*
9+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
10+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
11+
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
12+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
13+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
14+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
15+
* SOFTWARE.
16+
*/
17+
18+
package it.security;
19+
20+
import com.jcabi.http.mock.MkAnswer;
21+
import git.tracehub.pmo.PmoApplication;
22+
import git.tracehub.pmo.security.IdpToken;
23+
import it.PostgresIntegration;
24+
import it.ServerIntegration;
25+
import java.net.HttpURLConnection;
26+
import org.hamcrest.MatcherAssert;
27+
import org.hamcrest.core.IsEqual;
28+
import org.junit.jupiter.api.Test;
29+
import org.mockito.Mockito;
30+
import org.springframework.boot.test.context.SpringBootTest;
31+
import org.springframework.security.oauth2.jwt.Jwt;
32+
import org.springframework.test.context.ActiveProfiles;
33+
34+
/**
35+
* Integration tests for {@link IdpToken}.
36+
*
37+
* @since 0.0.0
38+
*/
39+
@ActiveProfiles("web")
40+
@SpringBootTest(
41+
classes = PmoApplication.class,
42+
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT
43+
)
44+
@SuppressWarnings("JTCOP.RuleAllTestsHaveProductionClass")
45+
final class IdpTokenIT
46+
implements ServerIntegration, PostgresIntegration {
47+
48+
@Test
49+
void retrievesIdpTokenSuccessfully() {
50+
final String url = ServerIntegration.SERVER.home().toString();
51+
final String expected = "token";
52+
ServerIntegration.SERVER.next(
53+
new MkAnswer.Simple(
54+
HttpURLConnection.HTTP_OK,
55+
"access_token=%s&expires_in=3600&token_type=bearer"
56+
.formatted(expected)
57+
)
58+
);
59+
final String token = new IdpToken(
60+
Mockito.mock(Jwt.class),
61+
"provider",
62+
url.substring(0, url.length() - 1)
63+
).value();
64+
MatcherAssert.assertThat(
65+
"Access token %s isn't correct".formatted(token),
66+
token,
67+
new IsEqual<>(expected)
68+
);
69+
}
70+
71+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
application:
2+
title: IT
3+
version: 0.0.1
4+
spring:
5+
datasource:
6+
username: test
7+
password: test
8+
liquibase:
9+
user: test
10+
password: test
11+
security:
12+
oauth2:
13+
resourceserver:
14+
jwt:
15+
issuer-uri: url

0 commit comments

Comments
 (0)