Skip to content

Commit

Permalink
[type:Integration Test] add integrated-test of Oauth2 plugin (apache#…
Browse files Browse the repository at this point in the history
…3848)

* test oauth

* test oauth

* test oauth

* test delete spring.oauth

* test update oauth version

* test delete oauth dependency

* test all workflow

* fix ci

* fix ci by update url

* fix ci by update example

* fix ci by delete example dependency

* fix ci by add example-oauth

* fix ci

* update test case

* fix urls

* fix ci

* fix ci

* fix ci

* fix ci

* fix ci

* fix ci by delete oauth yml

* update yaml
  • Loading branch information
erdengk authored Aug 29, 2022
1 parent a13a935 commit 22546ae
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.shenyu.examples.http.controller;

import org.apache.shenyu.client.springmvc.annotation.ShenyuSpringMvcClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
* OauthController.
*/
@RestController
@RequestMapping("/oauth")
@ShenyuSpringMvcClient("/oauth")
public class OauthController {

/**
* Test oauth2 code request.
*
* @return String
*/
@GetMapping("/authorize")
public String testCode() {
return "authorize";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,26 @@ services:
networks:
- shenyu

shenyu-examples-http:
deploy:
resources:
limits:
memory: 2048M
container_name: shenyu-examples-http
image: shenyu-examples-http:latest
restart: always
healthcheck:
test: [ "CMD", "wget", "http://shenyu-examples-http:8189/test/path/123?name=tom" ]
timeout: 2s
retries: 30
ports:
- "8189:8189"
depends_on:
shenyu-integrated-test-https:
condition: service_healthy
networks:
- shenyu

networks:
shenyu:
name: shenyu
8 changes: 8 additions & 0 deletions shenyu-integrated-test/shenyu-integrated-test-https/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@
<artifactId>shenyu-integrated-test-common</artifactId>
<version>${project.version}</version>
</dependency>
<!-- apache shenyu oauth2 plugin start-->
<dependency>
<groupId>org.apache.shenyu</groupId>
<artifactId>shenyu-spring-boot-starter-plugin-oauth2</artifactId>
<version>${project.version}</version>
</dependency>
<!-- apache shenyu oauth2 plugin end-->

</dependencies>

<profiles>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ server:
spring:
main:
allow-bean-definition-overriding: true
allow-circular-references: true
application:
name: shenyu-bootstrap

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.shenyu.integrated.test.https;

import org.apache.shenyu.common.enums.PluginEnum;
import org.apache.shenyu.integratedtest.common.AbstractPluginDataInit;
import org.apache.shenyu.integratedtest.common.helper.HttpHelper;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.assertNotNull;

public class Oauth2PluginTest extends AbstractPluginDataInit {

@BeforeEach
public void setup() throws IOException {
String pluginResult = initPlugin(PluginEnum.OAUTH2.getName(), "");
assertThat(pluginResult, is("success"));
}

@Test
public void testOauthPass() throws ExecutionException, InterruptedException {
Map<String, Object> headers = new HashMap<>();
Future<String> resp = this.getService().submit(() -> HttpHelper.INSTANCE.getHttpService("http://localhost:8189/oauth/authorize", headers, String.class));
assertNotNull(resp.get());
}

}

0 comments on commit 22546ae

Please sign in to comment.