Integration test launching both servers
This commit is contained in:
committed by
Joe Grandja
parent
8fedbb0d97
commit
01c3ebdecb
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package sample;
|
||||
package sample.authorizationserver;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package sample.config;
|
||||
package sample.authorizationserver.config;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package sample.config;
|
||||
package sample.authorizationserver.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
@@ -11,4 +11,7 @@ dependencies {
|
||||
compile 'org.webjars:webjars-locator-core'
|
||||
compile 'org.webjars:bootstrap:3.4.1'
|
||||
compile 'org.webjars:jquery:3.4.1'
|
||||
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
||||
testImplementation project(':spring-security-samples-boot-oauth2-integrated-authorizationserver')
|
||||
testImplementation project(':spring-security-samples-boot-oauth2-integrated-resourceserver')
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package sample;
|
||||
package sample.client;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package sample.config;
|
||||
package sample.client.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package sample.config;
|
||||
package sample.client.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package sample.web;
|
||||
package sample.client.web;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.security.oauth2.client.OAuth2AuthorizedClient;
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package sample.web;
|
||||
package sample.client.web;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
@@ -0,0 +1,70 @@
|
||||
package sample.client;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import sample.authorizationserver.OAuth2AuthorizationServerApplication;
|
||||
import sample.resourceserver.OAuth2ResourceServerApplication;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = OAuth2ClientApplication.class)
|
||||
@AutoConfigureMockMvc
|
||||
public class OAuth2ClientApplicationTest {
|
||||
|
||||
private ConfigurableApplicationContext authorizationServer;
|
||||
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
private ConfigurableApplicationContext resourceServer;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
authorizationServer = new SpringApplicationBuilder(OAuth2AuthorizationServerApplication.class)
|
||||
.properties("spring.config.name:embeddedauthorizationserver")
|
||||
.properties("server.port:9000")
|
||||
.application()
|
||||
.run();
|
||||
|
||||
resourceServer = new SpringApplicationBuilder(OAuth2ResourceServerApplication.class)
|
||||
.properties("spring.config.name:embeddedresourceserver")
|
||||
.properties("spring.security.oauth2.resourceserver.jwt.jwk-set-uri:http://auth-server:9000/oauth2/jwks")
|
||||
.properties("server.port:8090")
|
||||
.application()
|
||||
.run();
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
authorizationServer.stop();
|
||||
resourceServer.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void index() throws Exception {
|
||||
mockMvc
|
||||
.perform(get("/index"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().string(containsString("Client Credentials")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void authorize() throws Exception {
|
||||
mockMvc
|
||||
.perform(get("/authorize?grant_type=client_credentials"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().string(containsString("Message 1")));
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package sample;
|
||||
package sample.resourceserver;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package sample.config;
|
||||
package sample.resourceserver.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package sample.web;
|
||||
package sample.resourceserver.web;
|
||||
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
Reference in New Issue
Block a user