Skip to content

Commit

Permalink
Merge branch 'master' into rewritting-openapi-601
Browse files Browse the repository at this point in the history
  • Loading branch information
predic8 authored Jul 14, 2023
2 parents 32e8705 + 619de37 commit c87f11d
Show file tree
Hide file tree
Showing 9 changed files with 118 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Content-Type: application/json

###

GET localhost:2000/search?limit=10&page=2
GET http://localhost:2000/search?limit=10&page=2

###

Expand Down
6 changes: 2 additions & 4 deletions distribution/examples/openapi/validation-simple/requests.http
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@

### Valid request, should work

POST /persons
Host: localhost:2000
POST http://localhost:2000/persons
Content-Type: application/json

{
Expand All @@ -22,8 +21,7 @@ Content-Type: application/json

### Invalid request, should fail

POST /persons
Host: localhost:2000
POST http://localhost:2000/persons
Content-Type: application/json

{
Expand Down
36 changes: 12 additions & 24 deletions distribution/examples/openapi/validation/requests.http
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,24 @@


### Valid request, should work => 200 Ok
GET /demo-api/v2/persons?limit=10
Host: localhost:2000
GET http://localhost:2000/demo-api/v2/persons?limit=10

### Wrong path => 404 Not Found
GET /demo-api/v2/wrong
Host: localhost:2000
GET http://localhost:2000/demo-api/v2/wrong

### Limit greater than 100 => 400 Bad Request
GET /demo-api/v2/persons?limit=200
Host: localhost:2000
GET http://localhost:2000/demo-api/v2/persons?limit=200

### Valid => 201 Ok
PUT /demo-api/v2/persons/4077C19D-2C1D-427B-B2DD-FC3112CE89D1
Host: localhost:2000
PUT http://localhost:2000/demo-api/v2/persons/4077C19D-2C1D-427B-B2DD-FC3112CE89D1
Content-Type: application/json

{
"name": "Jan Vermeer"
}

### Invalid UUID, email and enum => 400 Bad Request
PUT /demo-api/v2/persons/4077C19D-2C1D-427B-B2+DDFC3112CE89D1
Host: localhost:2000
PUT http://localhost:2000/demo-api/v2/persons/4077C19D-2C1D-427B-B2+DDFC3112CE89D1
Content-Type: application/json

{
Expand All @@ -43,24 +38,21 @@ Content-Type: application/json
}

### Wrong Content-Type => 415 Unsupported Mediatype
PUT /demo-api/v2/persons/4077C19D-2C1D-427B-B2DD-FC3112CE89D1
Host: localhost:2000
PUT http://localhost:2000/demo-api/v2/persons/4077C19D-2C1D-427B-B2DD-FC3112CE89D1
Content-Type: application/xml

<name>Jan</name>

### Required property is missing => 400 Bad Request
PUT /demo-api/v2/persons/4077C19D-2C1D-427B-B2DD-FC3112CE89D1
Host: localhost:2000
PUT http://localhost:2000/demo-api/v2/persons/4077C19D-2C1D-427B-B2DD-FC3112CE89D1
Content-Type: application/json

{
"email": "jan@predic8.de"
}

### Additional property role => 400 Bad Request
PUT /demo-api/v2/persons/4077C19D-2C1D-427B-B2DD-FC3112CE89D1
Host: localhost:2000
PUT http://localhost:2000/demo-api/v2/persons/4077C19D-2C1D-427B-B2DD-FC3112CE89D1
Content-Type: application/json

{
Expand All @@ -69,8 +61,7 @@ Content-Type: application/json
}

### Wrong regex pattern => 400 Bad Request
PUT /demo-api/v2/persons/4077C19D-2C1D-427B-B2DD-FC3112CE89D1
Host: localhost:2000
PUT http://localhost:2000/demo-api/v2/persons/4077C19D-2C1D-427B-B2DD-FC3112CE89D1
Content-Type: application/json

{
Expand All @@ -79,8 +70,7 @@ Content-Type: application/json
}

### Nested Object => 201 Created
PUT /demo-api/v2/persons/4077C19D-2C1D-427B-B2DD-FC3112CE89D1
Host: localhost:2000
PUT http://localhost:2000/demo-api/v2/persons/4077C19D-2C1D-427B-B2DD-FC3112CE89D1
Content-Type: application/json

{
Expand All @@ -94,8 +84,7 @@ Content-Type: application/json
}

### OneOf with wrong string pattern => 400 Bad Request
PUT /demo-api/v2/persons/4077C19D-2C1D-427B-B2DD-FC3112CE89D1
Host: localhost:2000
PUT http://localhost:2000/demo-api/v2/persons/4077C19D-2C1D-427B-B2DD-FC3112CE89D1
Content-Type: application/json

{
Expand All @@ -109,8 +98,7 @@ Content-Type: application/json
}

### OneOf with right integer => 201 Created
PUT /demo-api/v2/persons/4077C19D-2C1D-427B-B2DD-FC3112CE89D1
Host: localhost:2000
PUT http://localhost:2000/demo-api/v2/persons/4077C19D-2C1D-427B-B2DD-FC3112CE89D1
Content-Type: application/json

{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@echo off
if not "%MEMBRANE_HOME%" == "" goto homeSet
set "MEMBRANE_HOME=%cd%\..\.."
set "MEMBRANE_HOME=%cd%\..\..\.."
echo "%MEMBRANE_HOME%"
if exist "%MEMBRANE_HOME%\service-proxy.bat" goto homeOk

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ terminate() {
homeNotSet() {
echo "MEMBRANE_HOME variable is not set"

if [ -f "`pwd`/../../starter.jar" ]
if [ -f "`pwd`/../../../starter.jar" ]
then
export MEMBRANE_HOME="`pwd`/../.."
export MEMBRANE_HOME="`pwd`/../../.."
homeSet
else
terminate
Expand Down
23 changes: 12 additions & 11 deletions distribution/router/conf/proxies-full-sample.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,6 @@
maxDays="30" />

<router hotDeploy="true" retryInitInterval="30000" exchangeStore="myFileExchangeStore" >

<!-- Configure all outbound HTTP connections for this router. -->
<httpClientConfig>
<!-- configure timeouts -->
<connection timeout="10000" keepAliveTimeout="4000" />
<!-- use a HTTP proxy -->
<!-- <proxy host="proxy.predic8.de" port="3128" /> -->
<!-- use Basic Authentication -->
<authentication username="john" password="secret" />
</httpClientConfig>

<!--
Configure the global interceptor chain used to handle all incoming HTTP requests.
Expand Down Expand Up @@ -142,7 +132,18 @@
executed so far will get the chance to alter the response.
The unwinding takes place in the reverse order.
-->
<httpClient />
<httpClient>
<!-- Configure all outbound HTTP connections for this router. -->
<httpClientConfig>
<!-- configure timeouts -->
<connection timeout="10000" keepAliveTimeout="4000" />
<!-- use a HTTP proxy -->
<!-- <proxy host="proxy.predic8.de" port="3128" /> -->
<!-- use Basic Authentication -->
<authentication username="john" password="secret" />
</httpClientConfig>
</httpClient>

</transport>

<!--
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
package com.predic8.membrane.examples;

import com.predic8.membrane.errorhandling.OpenAPIConfigErrorTest;
import com.predic8.membrane.examples.config.DefaultConfigAdminConsoleTest;
import com.predic8.membrane.examples.config.ProxiesXMLOfflineTest;
import com.predic8.membrane.examples.config.ProxiesXMLSecurityTest;
import com.predic8.membrane.examples.config.*;
import com.predic8.membrane.examples.env.ConsistentVersionNumbers;
import com.predic8.membrane.examples.env.JavaLicenseInfoTest;
import com.predic8.membrane.examples.tests.*;
Expand Down Expand Up @@ -69,6 +67,7 @@

ProxiesXMLOfflineTest.class,
ProxiesXMLSecurityTest.class,
ProxiesXMLFullSampleTest.class,

// Not an example test. Maybe we can find a better location?
OpenAPIConfigErrorTest.class,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/* Copyright 2022 predic8 GmbH, www.predic8.com
Licensed 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 com.predic8.membrane.examples.config;

import com.predic8.membrane.examples.util.*;
import io.restassured.*;
import io.restassured.filter.log.*;
import org.junit.jupiter.api.*;

import java.io.*;

import static com.predic8.membrane.core.http.MimeType.*;
import static io.restassured.RestAssured.*;

public class ProxiesXMLFullSampleTest extends AbstractSampleMembraneStartStopTestcase {

@Override
protected String getExampleDirName() {
return "..";
}

@BeforeEach
void startMembrane() throws IOException, InterruptedException {
process = new Process2.Builder().in(baseDir).script("service-proxy").parameters("-c conf/proxies-full-sample.xml").waitForMembrane().start();

// Dump HTTP
RestAssured.filters(new RequestLoggingFilter(), new ResponseLoggingFilter());
}


@Test
void staticWeb() {
// @formatter:off
get("http://localhost:2001/static/proxies.xml")
.then().assertThat()
.statusCode(200)
.contentType(TEXT_XML);
// @formatter:on
}

@Test
void adminConsoleWithoutAuth() {
// @formatter:off
get("http://localhost:9000/admin")
.then().assertThat()
.statusCode(401);
// @formatter:on
}

@Test
void adminConsoleWithAuth() {
// @formatter:off
given().
auth().basic("admin","membrane").
when().
get("http://localhost:9000/admin").
then().assertThat()
.statusCode(200)
.contentType(TEXT_HTML);
// @formatter:on
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,16 @@ public void normalAPI() {
.contentType(APPLICATION_JSON)
.body("apis[0]['name']",equalTo("Shop API Showcase"));
}

@Test
void adminConsole() {
// @formatter:off
given().
when().
get("http://localhost:9000/admin").
then().assertThat()
.statusCode(200)
.contentType(TEXT_HTML);
// @formatter:on
}
}

0 comments on commit c87f11d

Please sign in to comment.