From a73d64b464ee8fe348dc229d7552f0bb64486b1b Mon Sep 17 00:00:00 2001 From: "kirill.turutin" Date: Tue, 30 Jul 2019 14:21:24 +0300 Subject: [PATCH 01/12] tmp --- browserup-proxy-rest-clients/build.gradle | 144 ++++++++++++++++++ .../src/main/resources/swagger-config.json | 18 +++ .../src/test/resources/log4j2-test.json | 23 +++ .../bup/rest/swagger/CustomOpenApiReader.java | 58 +++++++ .../src/main/resources/swagger-config.yaml | 1 + settings.gradle | 1 + 6 files changed, 245 insertions(+) create mode 100644 browserup-proxy-rest-clients/build.gradle create mode 100644 browserup-proxy-rest-clients/src/main/resources/swagger-config.json create mode 100644 browserup-proxy-rest-clients/src/test/resources/log4j2-test.json create mode 100644 browserup-proxy-rest/src/main/java/com/browserup/bup/rest/swagger/CustomOpenApiReader.java diff --git a/browserup-proxy-rest-clients/build.gradle b/browserup-proxy-rest-clients/build.gradle new file mode 100644 index 000000000..bce74ab64 --- /dev/null +++ b/browserup-proxy-rest-clients/build.gradle @@ -0,0 +1,144 @@ +/* + * Modifications Copyright (c) 2019 BrowserUp, Inc. + */ + +plugins { + id 'java-library' + id 'groovy' + id "io.swagger.core.v3.swagger-gradle-plugin" version "2.0.8" + id "org.openapi.generator" version "4.0.0-beta3" +} + +resolve { + outputFileName = 'openapi' + outputFormat = 'YAML' + prettyPrint = 'TRUE' + openApiFile = file("src/main/resources/swagger-config.json") + classpath = sourceSets.main.runtimeClasspath + readerClass = "com.browserup.bup.rest.swagger.CustomOpenApiReader" + resourcePackages = ['com.browserup.bup.rest.resource'] + outputPath = 'build/swagger' +} + +openApiGenerate { + generatorName = "python" + inputSpec = "$buildDir/swagger/openapi.yaml".toString() + outputDir = "$buildDir/swagger-clients/python/".toString() + apiPackage = "com.browserup.bup.rest" + invokerPackage = "com.browserup.bup.rest.client.invoker" + modelPackage = "com.browserup.bup.rest.client.model" + systemProperties = [ + modelDocs: "false" + ] + skipValidateSpec = true + logToStderr = true + generateAliasAsModel = false +} + +task openApiGeneratePythonClient(type: org.openapitools.generator.gradle.plugin.tasks.GenerateTask) { + dependsOn 'resolve' + def language = "python" + generatorName = language + inputSpec = "$buildDir/swagger/openapi.yaml".toString() + outputDir = "$buildDir/swagger-clients/$language/".toString() + apiPackage = "com.browserup.bup.rest" + invokerPackage = "com.browserup.bup.rest.client.invoker" + modelPackage = "com.browserup.bup.rest.client.model" + systemProperties = [ + modelDocs: "false" + ] + skipValidateSpec = true + logToStderr = true + generateAliasAsModel = false +} + +task openApiGenerateRubyClient(type: org.openapitools.generator.gradle.plugin.tasks.GenerateTask) { + dependsOn 'resolve' + def language = 'ruby' + generatorName = language + inputSpec = "$buildDir/swagger/openapi.yaml".toString() + outputDir = "$buildDir/swagger-clients/$language/".toString() + apiPackage = "com.browserup.bup.rest" + invokerPackage = "com.browserup.bup.rest.client.invoker" + modelPackage = "com.browserup.bup.rest.client.model" + systemProperties = [ + modelDocs: "false" + ] + skipValidateSpec = true + logToStderr = true + generateAliasAsModel = false +} + +task openApiGenerateJavaScriptClient(type: org.openapitools.generator.gradle.plugin.tasks.GenerateTask) { + dependsOn 'resolve' + def language = 'javascript' + generatorName = language + inputSpec = "$buildDir/swagger/openapi.yaml".toString() + outputDir = "$buildDir/swagger-clients/$language/".toString() + apiPackage = "com.browserup.bup.rest" + invokerPackage = "com.browserup.bup.rest.client.invoker" + modelPackage = "com.browserup.bup.rest.client.model" + systemProperties = [ + modelDocs: "false" + ] + skipValidateSpec = true + logToStderr = true + generateAliasAsModel = false +} + +task openApiGenerateClients() { + dependsOn 'openApiGeneratePythonClient' + dependsOn 'openApiGenerateRubyClient' + dependsOn 'openApiGenerateJavaScriptClient' +} + +archivesBaseName = 'browserup-proxy-rest-clients' + +ext { + jerseyVersion = '2.29' +} + +dependencies { + implementation project(':browserup-proxy-core') + implementation project(':browserup-proxy-rest') + + implementation 'com.google.guava:guava:27.0.1-jre' + implementation 'com.google.inject:guice:4.2.2' + implementation 'com.google.inject.extensions:guice-servlet:4.2.2' + implementation 'com.google.inject.extensions:guice-multibindings:4.2.2' + implementation 'com.google.sitebricks:sitebricks:0.8.11' + implementation 'io.netty:netty-all:4.1.37.Final' + implementation 'net.sf.jopt-simple:jopt-simple:5.0.4' + implementation "org.eclipse.jetty:jetty-server:${jettyVersion}" + implementation "org.eclipse.jetty:jetty-servlet:${jettyVersion}" + implementation 'org.slf4j:jcl-over-slf4j:1.7.26' + implementation 'org.apache.commons:commons-lang3:3.9' + + implementation "org.glassfish.jersey.containers:jersey-container-servlet-core:${jerseyVersion}" + implementation "org.glassfish.jersey.media:jersey-media-json-jackson:${jerseyVersion}" + implementation "org.glassfish.jersey.inject:jersey-hk2:${jerseyVersion}" + implementation "org.glassfish.jersey.ext:jersey-bean-validation:${jerseyVersion}" + + implementation 'io.swagger.core.v3:swagger-jaxrs2:2.0.8' + implementation 'io.swagger.core.v3:swagger-core:2.0.8' + implementation 'io.swagger.core.v3:swagger-integration:2.0.8' + implementation 'io.swagger.core.v3:swagger-jaxrs2-servlet-initializer:2.0.8' + implementation 'io.swagger.core.v3:swagger-models:2.0.8' + + testImplementation project(':browserup-proxy-mitm') + + testImplementation 'junit:junit:4.12' + testImplementation "org.apache.logging.log4j:log4j-api:${log4jVersion}" + testImplementation "org.apache.logging.log4j:log4j-core:${log4jVersion}" + testImplementation "org.apache.logging.log4j:log4j-slf4j-impl:${log4jVersion}" + testImplementation 'org.codehaus.groovy:groovy-all:2.5.7' + testImplementation 'org.codehaus.groovy.modules.http-builder:http-builder:0.7.2' + testImplementation 'org.hamcrest:hamcrest:2.1' + testImplementation 'org.hamcrest:hamcrest-library:2.1' + testImplementation 'org.mockito:mockito-core:3.0.0' + testImplementation 'org.seleniumhq.selenium:selenium-api:3.4.0' + testImplementation 'org.awaitility:awaitility:3.1.6' + testImplementation 'xyz.rogfam:littleproxy:2.0.0-beta-3' + testImplementation 'com.github.tomakehurst:wiremock-jre8:2.24.0' +} + diff --git a/browserup-proxy-rest-clients/src/main/resources/swagger-config.json b/browserup-proxy-rest-clients/src/main/resources/swagger-config.json new file mode 100644 index 000000000..40dad6bc1 --- /dev/null +++ b/browserup-proxy-rest-clients/src/main/resources/swagger-config.json @@ -0,0 +1,18 @@ +{ + "resourcePackages" : [ + "com.browserup.bup.rest.resource" + ], + "openapi" : "3.0.1", + "info": { + "version": "1.0", + "title": "BrowserUp Proxy API", + "description": "BrowserUp Proxy API", + "contact": { + "email": "hello@browserup.com" + }, + "license": { + "name": "Apache 2.0", + "url": "http://www.apache.org/licenses/LICENSE-2.0.html" + } + } +} \ No newline at end of file diff --git a/browserup-proxy-rest-clients/src/test/resources/log4j2-test.json b/browserup-proxy-rest-clients/src/test/resources/log4j2-test.json new file mode 100644 index 000000000..f3e5e72ec --- /dev/null +++ b/browserup-proxy-rest-clients/src/test/resources/log4j2-test.json @@ -0,0 +1,23 @@ +{ + "configuration" : { + "name": "test", + "appenders": { + "Console": { + "name": "console", + "target": "SYSTEM_OUT", + "PatternLayout": { + "pattern": "%-7r %date %level [%thread] %logger - %msg%n" + } + } + }, + + "loggers": { + "root": { + "level": "info", + "appender-ref": { + "ref": "console" + } + } + } + } +} \ No newline at end of file diff --git a/browserup-proxy-rest/src/main/java/com/browserup/bup/rest/swagger/CustomOpenApiReader.java b/browserup-proxy-rest/src/main/java/com/browserup/bup/rest/swagger/CustomOpenApiReader.java new file mode 100644 index 000000000..5d5ca6d8f --- /dev/null +++ b/browserup-proxy-rest/src/main/java/com/browserup/bup/rest/swagger/CustomOpenApiReader.java @@ -0,0 +1,58 @@ +package com.browserup.bup.rest.swagger; + +import com.fasterxml.jackson.annotation.JsonView; +import com.fasterxml.jackson.databind.introspect.AnnotatedMethod; +import io.swagger.v3.jaxrs2.Reader; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.integration.api.OpenAPIConfiguration; +import io.swagger.v3.oas.integration.api.OpenApiReader; +import io.swagger.v3.oas.models.ExternalDocumentation; +import io.swagger.v3.oas.models.OpenAPI; +import io.swagger.v3.oas.models.Operation; +import io.swagger.v3.oas.models.parameters.Parameter; +import io.swagger.v3.oas.models.parameters.RequestBody; +import io.swagger.v3.oas.models.responses.ApiResponses; +import io.swagger.v3.oas.models.security.SecurityRequirement; +import io.swagger.v3.oas.models.servers.Server; +import org.apache.commons.lang3.StringUtils; + +import javax.ws.rs.Consumes; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import java.lang.reflect.Method; +import java.util.*; + +public class CustomOpenApiReader extends Reader { + @Override + protected String getOperationId(String operationId) { + return super.getOperationId(operationId); + } + + @Override + public Operation parseMethod(Method method, List globalParameters, Produces methodProduces, Produces classProduces, Consumes methodConsumes, Consumes classConsumes, List classSecurityRequirements, Optional classExternalDocs, Set classTags, List classServers, boolean isSubresource, RequestBody parentRequestBody, ApiResponses parentResponses, JsonView jsonViewAnnotation, ApiResponse[] classResponses, AnnotatedMethod annotatedMethod) { + Operation operation = super.parseMethod(method, globalParameters, methodProduces, classProduces, methodConsumes, classConsumes, classSecurityRequirements, classExternalDocs, classTags, classServers, isSubresource, parentRequestBody, parentResponses, jsonViewAnnotation, classResponses, annotatedMethod); + + Arrays.stream(method.getDeclaringClass().getAnnotations()) + .filter(Path.class::isInstance) + .filter(path -> StringUtils.isNotEmpty(((Path) path).value())) + .findFirst() + .map(path -> ((Path) path).value()) + .flatMap(this::createOperationIdPrefixByPathAnnotation) + .map(operationIdPrefix -> { + return operationIdPrefix.equals(method.getName()) ? + method.getName() : + operationIdPrefix + StringUtils.capitalize(method.getName()); + }) + .ifPresent(operation::setOperationId); + + return operation; + } + + private Optional createOperationIdPrefixByPathAnnotation(String pathAnnoValue) { + String[] pathElements = pathAnnoValue.split("/"); + if (pathElements.length > 0) { + return Optional.of(pathElements[pathElements.length - 1]); + } + return Optional.empty(); + } +} diff --git a/browserup-proxy-rest/src/main/resources/swagger-config.yaml b/browserup-proxy-rest/src/main/resources/swagger-config.yaml index 70bc72143..22c4d700a 100644 --- a/browserup-proxy-rest/src/main/resources/swagger-config.yaml +++ b/browserup-proxy-rest/src/main/resources/swagger-config.yaml @@ -1,6 +1,7 @@ resourcePackages: - com.browserup.bup.rest.resource prettyPrint: true +readerClass: com.browserup.bup.rest.swagger.CustomOpenApiReader cacheTTL: 0 openAPI: info: diff --git a/settings.gradle b/settings.gradle index 1c6cc46aa..25c37126d 100644 --- a/settings.gradle +++ b/settings.gradle @@ -6,3 +6,4 @@ include 'browserup-proxy-core' include 'browserup-proxy-dist' include 'browserup-proxy-rest' include 'browserup-proxy-mitm' +include 'browserup-proxy-rest-clients' From 71ec2378a747dd0f9e957c7d4cb80240a03ab250 Mon Sep 17 00:00:00 2001 From: "kirill.turutin" Date: Wed, 31 Jul 2019 14:42:23 +0300 Subject: [PATCH 02/12] remarks; ruby client test - in progress --- browserup-proxy-rest-clients/build.gradle | 119 +++-------- .../groovy/com/FindHarEntriesRestTest.groovy | 89 +++++++++ .../com/WithRunningProxyRestTest.groovy | 187 ++++++++++++++++++ .../src/test/ruby/.rspec | 3 + .../src/test/ruby/Gemfile | 4 + .../src/test/ruby/Gemfile.lock | 36 ++++ .../src/test/ruby/spec/test_client_spec.rb | 16 ++ browserup-proxy-rest/build.gradle | 12 ++ .../entries/EntriesProxyResource.java | 7 + .../bup/rest/swagger/CustomOpenApiReader.java | 61 +++++- build.gradle | 6 +- 11 files changed, 447 insertions(+), 93 deletions(-) create mode 100644 browserup-proxy-rest-clients/src/test/groovy/com/FindHarEntriesRestTest.groovy create mode 100644 browserup-proxy-rest-clients/src/test/groovy/com/WithRunningProxyRestTest.groovy create mode 100644 browserup-proxy-rest-clients/src/test/ruby/.rspec create mode 100644 browserup-proxy-rest-clients/src/test/ruby/Gemfile create mode 100644 browserup-proxy-rest-clients/src/test/ruby/Gemfile.lock create mode 100644 browserup-proxy-rest-clients/src/test/ruby/spec/test_client_spec.rb diff --git a/browserup-proxy-rest-clients/build.gradle b/browserup-proxy-rest-clients/build.gradle index bce74ab64..ed516ef57 100644 --- a/browserup-proxy-rest-clients/build.gradle +++ b/browserup-proxy-rest-clients/build.gradle @@ -20,111 +20,48 @@ resolve { outputPath = 'build/swagger' } -openApiGenerate { - generatorName = "python" - inputSpec = "$buildDir/swagger/openapi.yaml".toString() - outputDir = "$buildDir/swagger-clients/python/".toString() - apiPackage = "com.browserup.bup.rest" - invokerPackage = "com.browserup.bup.rest.client.invoker" - modelPackage = "com.browserup.bup.rest.client.model" - systemProperties = [ - modelDocs: "false" - ] - skipValidateSpec = true - logToStderr = true - generateAliasAsModel = false -} - -task openApiGeneratePythonClient(type: org.openapitools.generator.gradle.plugin.tasks.GenerateTask) { - dependsOn 'resolve' - def language = "python" - generatorName = language - inputSpec = "$buildDir/swagger/openapi.yaml".toString() - outputDir = "$buildDir/swagger-clients/$language/".toString() - apiPackage = "com.browserup.bup.rest" - invokerPackage = "com.browserup.bup.rest.client.invoker" - modelPackage = "com.browserup.bup.rest.client.model" - systemProperties = [ - modelDocs: "false" - ] - skipValidateSpec = true - logToStderr = true - generateAliasAsModel = false -} - -task openApiGenerateRubyClient(type: org.openapitools.generator.gradle.plugin.tasks.GenerateTask) { - dependsOn 'resolve' - def language = 'ruby' - generatorName = language - inputSpec = "$buildDir/swagger/openapi.yaml".toString() - outputDir = "$buildDir/swagger-clients/$language/".toString() - apiPackage = "com.browserup.bup.rest" - invokerPackage = "com.browserup.bup.rest.client.invoker" - modelPackage = "com.browserup.bup.rest.client.model" - systemProperties = [ - modelDocs: "false" - ] - skipValidateSpec = true - logToStderr = true - generateAliasAsModel = false -} - -task openApiGenerateJavaScriptClient(type: org.openapitools.generator.gradle.plugin.tasks.GenerateTask) { - dependsOn 'resolve' - def language = 'javascript' - generatorName = language - inputSpec = "$buildDir/swagger/openapi.yaml".toString() - outputDir = "$buildDir/swagger-clients/$language/".toString() - apiPackage = "com.browserup.bup.rest" - invokerPackage = "com.browserup.bup.rest.client.invoker" - modelPackage = "com.browserup.bup.rest.client.model" - systemProperties = [ - modelDocs: "false" - ] - skipValidateSpec = true - logToStderr = true - generateAliasAsModel = false +def clientLanguages = [ + 'JavaScript', + 'Ruby', + 'Python' +] + +clientLanguages.each { lang -> + task "openApiGenerate${lang}Client"(type: org.openapitools.generator.gradle.plugin.tasks.GenerateTask) { + dependsOn 'resolve' + def language = lang.toLowerCase() + generatorName = language + inputSpec = "$buildDir/swagger/openapi.yaml".toString() + outputDir = "$buildDir/swagger-clients/$language/".toString() + apiPackage = 'com.browserup.bup.rest' + invokerPackage = 'com.browserup.bup.rest.client.invoker' + modelPackage = 'com.browserup.bup.rest.client.model' + systemProperties = [ + modelDocs: 'false' + ] + skipValidateSpec = true + logToStderr = true + generateAliasAsModel = false + } } task openApiGenerateClients() { - dependsOn 'openApiGeneratePythonClient' - dependsOn 'openApiGenerateRubyClient' - dependsOn 'openApiGenerateJavaScriptClient' + clientLanguages.each { lang -> + dependsOn "openApiGenerate${lang}Client" + } } archivesBaseName = 'browserup-proxy-rest-clients' -ext { - jerseyVersion = '2.29' -} - dependencies { implementation project(':browserup-proxy-core') implementation project(':browserup-proxy-rest') - implementation 'com.google.guava:guava:27.0.1-jre' implementation 'com.google.inject:guice:4.2.2' implementation 'com.google.inject.extensions:guice-servlet:4.2.2' implementation 'com.google.inject.extensions:guice-multibindings:4.2.2' implementation 'com.google.sitebricks:sitebricks:0.8.11' - implementation 'io.netty:netty-all:4.1.37.Final' - implementation 'net.sf.jopt-simple:jopt-simple:5.0.4' - implementation "org.eclipse.jetty:jetty-server:${jettyVersion}" - implementation "org.eclipse.jetty:jetty-servlet:${jettyVersion}" - implementation 'org.slf4j:jcl-over-slf4j:1.7.26' - implementation 'org.apache.commons:commons-lang3:3.9' - - implementation "org.glassfish.jersey.containers:jersey-container-servlet-core:${jerseyVersion}" - implementation "org.glassfish.jersey.media:jersey-media-json-jackson:${jerseyVersion}" - implementation "org.glassfish.jersey.inject:jersey-hk2:${jerseyVersion}" - implementation "org.glassfish.jersey.ext:jersey-bean-validation:${jerseyVersion}" - - implementation 'io.swagger.core.v3:swagger-jaxrs2:2.0.8' - implementation 'io.swagger.core.v3:swagger-core:2.0.8' - implementation 'io.swagger.core.v3:swagger-integration:2.0.8' - implementation 'io.swagger.core.v3:swagger-jaxrs2-servlet-initializer:2.0.8' - implementation 'io.swagger.core.v3:swagger-models:2.0.8' - + testImplementation project(':browserup-proxy-mitm') testImplementation 'junit:junit:4.12' @@ -140,5 +77,7 @@ dependencies { testImplementation 'org.awaitility:awaitility:3.1.6' testImplementation 'xyz.rogfam:littleproxy:2.0.0-beta-3' testImplementation 'com.github.tomakehurst:wiremock-jre8:2.24.0' + } +build.finalizedBy(openApiGenerateClients) \ No newline at end of file diff --git a/browserup-proxy-rest-clients/src/test/groovy/com/FindHarEntriesRestTest.groovy b/browserup-proxy-rest-clients/src/test/groovy/com/FindHarEntriesRestTest.groovy new file mode 100644 index 000000000..5ba4432d0 --- /dev/null +++ b/browserup-proxy-rest-clients/src/test/groovy/com/FindHarEntriesRestTest.groovy @@ -0,0 +1,89 @@ +/* + * Modifications Copyright (c) 2019 BrowserUp, Inc. + */ + +package com + +import com.browserup.harreader.model.HarEntry +import com.fasterxml.jackson.databind.ObjectMapper +import com.github.tomakehurst.wiremock.client.WireMock +import groovyx.net.http.HttpResponseDecorator +import groovyx.net.http.Method +import org.apache.http.entity.ContentType +import org.hamcrest.Matchers +import org.junit.Test + +import static com.github.tomakehurst.wiremock.client.WireMock.getRequestedFor +import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo +import static org.junit.Assert.assertEquals +import static org.junit.Assert.assertThat + +class FindHarEntriesRestTest extends WithRunningProxyRestTest { + + @Override + String getUrlPath() { + return 'har/entries' + } + + @Test + void findHarEntryByUrlPattern() { + def urlToCatch = 'test' + def urlNotToCatch = 'missing' + def responseBody = 'success' + + mockTargetServerResponse(urlToCatch, responseBody) + mockTargetServerResponse(urlNotToCatch, responseBody) + + proxyManager.get()[0].newHar() + + requestToTargetServer(urlToCatch, responseBody) + requestToTargetServer(urlNotToCatch, responseBody) + + proxyRestServerClient.request(Method.GET, ContentType.APPLICATION_JSON) { req -> + def urlPattern = ".*${urlToCatch}" + uri.path = "/proxy/${proxy.port}/${urlPath}" + uri.query = [urlPattern: urlPattern] + response.success = { HttpResponseDecorator resp -> + HarEntry[] entries = new ObjectMapper().readValue(resp.entity.content, HarEntry[]) as HarEntry[] + assertThat('Expected to find only one entry', entries, Matchers.arrayWithSize(1)) + assertThat('Expected to find entry containing url from url filter pattern', + entries[0].request.url, Matchers.containsString(urlToCatch)) + assertThat('Expected to find no entries with urlNotToCatch filter', + entries[0].request.url, Matchers.not(Matchers.containsString(urlNotToCatch))) + } + } + + WireMock.verify(1, getRequestedFor(urlEqualTo("/${urlToCatch}"))) + WireMock.verify(1, getRequestedFor(urlEqualTo("/${urlNotToCatch}"))) + } + + @Test + void getEmptyEntriesArrayIfNoEntriesFoundByUrl() { + def urlToCatch = 'test' + def urlNotToCatch = 'missing' + def responseBody = 'success' + + mockTargetServerResponse(urlNotToCatch, responseBody) + + proxyManager.get()[0].newHar() + + targetServerClient.request(Method.GET, ContentType.WILDCARD) { req -> + uri.path = "/${urlNotToCatch}" + response.success = { _, reader -> + assertEquals(responseBody, reader.text) + } + } + + proxyRestServerClient.request(Method.GET, ContentType.APPLICATION_JSON) { req -> + def urlPattern = ".*${urlToCatch}" + uri.path = "/proxy/${proxy.port}/${urlPath}" + uri.query = [urlPattern: urlPattern] + response.success = { HttpResponseDecorator resp -> + HarEntry[] entries = new ObjectMapper().readValue(resp.entity.content, HarEntry[]) as HarEntry[] + assertThat('Expected get empty har entries array', entries, Matchers.arrayWithSize(0)) + } + } + + WireMock.verify(1, getRequestedFor(urlEqualTo("/${urlNotToCatch}"))) + } +} diff --git a/browserup-proxy-rest-clients/src/test/groovy/com/WithRunningProxyRestTest.groovy b/browserup-proxy-rest-clients/src/test/groovy/com/WithRunningProxyRestTest.groovy new file mode 100644 index 000000000..7dc6eeac2 --- /dev/null +++ b/browserup-proxy-rest-clients/src/test/groovy/com/WithRunningProxyRestTest.groovy @@ -0,0 +1,187 @@ +/* + * Modifications Copyright (c) 2019 BrowserUp, Inc. + */ + +package com + +import com.browserup.bup.BrowserUpProxyServer +import com.browserup.bup.proxy.ProxyManager +import com.browserup.bup.proxy.bricks.ProxyResource +import com.browserup.bup.proxy.guice.ConfigModule +import com.browserup.bup.proxy.guice.JettyModule +import com.browserup.bup.util.BrowserUpProxyUtil +import com.github.tomakehurst.wiremock.client.WireMock +import com.github.tomakehurst.wiremock.core.WireMockConfiguration +import com.github.tomakehurst.wiremock.junit.WireMockRule +import com.google.inject.Guice +import com.google.inject.Injector +import com.google.inject.servlet.GuiceServletContextListener +import com.google.sitebricks.SitebricksModule +import groovyx.net.http.HTTPBuilder +import groovyx.net.http.Method +import org.apache.http.entity.ContentType +import org.awaitility.Awaitility +import org.eclipse.jetty.server.Server +import org.eclipse.jetty.servlet.ServletContextHandler +import org.junit.After +import org.junit.Assert +import org.junit.Before +import org.junit.Rule +import org.slf4j.Logger +import org.slf4j.LoggerFactory + +import javax.servlet.ServletContextEvent +import java.util.concurrent.TimeUnit + +abstract class WithRunningProxyRestTest { + private static final Logger LOG = LoggerFactory.getLogger(ProxyManager) + + protected ProxyManager proxyManager + protected BrowserUpProxyServer proxy + protected Server restServer + + protected String[] getArgs() { + ['--port', '0'] as String[] + } + + abstract String getUrlPath(); + + String getFullUrlPath() { + return "/proxy/${proxy.port}/${urlPath}" + } + + protected int mockServerPort + protected int mockServerHttpsPort + + @Rule + public WireMockRule wireMockRule = new WireMockRule(WireMockConfiguration.options().port(0).httpsPort(0)) + + @Before + void setUp() throws Exception { + Injector injector = Guice.createInjector(new ConfigModule(args), new JettyModule(), new SitebricksModule() { + @Override + protected void configureSitebricks() { + scan(ProxyResource.class.getPackage()) + } + }) + + proxyManager = injector.getInstance(ProxyManager) + + LOG.debug("Starting BrowserUp Proxy version " + BrowserUpProxyUtil.versionString) + + new Thread(new Runnable() { + @Override + void run() { + startRestServer(injector) + } + }).start() + + LOG.debug("Waiting till BrowserUp Rest server is started") + + Awaitility.await().atMost(10, TimeUnit.SECONDS).until({ -> restServer != null && restServer.isStarted() }) + + LOG.debug("BrowserUp Rest server is started successfully") + + LOG.debug("Waiting till BrowserUp Proxy server is started") + + proxy = proxyManager.create(0) + + Awaitility.await().atMost(5, TimeUnit.SECONDS).until({ -> proxyManager.get().size() > 0 }) + + LOG.debug("BrowserUp Proxy server is started successfully") + + mockServerPort = wireMockRule.port(); + mockServerHttpsPort = wireMockRule.httpsPort(); + + waitForProxyServer() + } + + def waitForProxyServer() { + Awaitility.await().atMost(5, TimeUnit.SECONDS).until({ -> + def successful = false + proxyRestServerClient.request(Method.GET, ContentType.TEXT_PLAIN) { req -> + uri.path = "/proxy" + response.success = { _, reader -> + successful = true + } + response.failure = { _, reader -> + successful = false + } + } + return successful + }) + } + + HTTPBuilder getTargetServerClient() { + def http = new HTTPBuilder("http://localhost:${mockServerPort}") + http.setProxy('localhost', proxy.port, 'http') + http + } + + HTTPBuilder getProxyRestServerClient() { + new HTTPBuilder("http://localhost:${restServer.connectors[0].localPort}") + } + + def sendGetToProxyServer(Closure configClosure) { + proxyRestServerClient.request(Method.GET, ContentType.WILDCARD, configClosure) + } + + void requestToTargetServer(url, expectedResponse) { + targetServerClient.request(Method.GET, ContentType.TEXT_PLAIN) { req -> + uri.path = "/${url}" + response.success = { _, reader -> + Assert.assertEquals(expectedResponse, reader.text) + } + response.failure = { _, reader -> + Assert.assertEquals(expectedResponse, reader.text) + } + } + } + + @After + void tearDown() throws Exception { + LOG.debug('Stopping proxy servers') + for (def proxyServer : proxyManager.get()) { + try { + proxyManager.delete(proxyServer.port) + } catch (Exception ex) { + LOG.error('Error while stopping proxy servers', ex) + } + } + + if (restServer != null) { + LOG.debug('Stopping rest proxy server') + try { + restServer.stop() + } catch (Exception ex) { + LOG.error('Error while stopping rest proxy server', ex) + } + } + } + + private void startRestServer(Injector injector) { + restServer = injector.getInstance(Server.class) + def contextListener = new GuiceServletContextListener() { + @Override + protected Injector getInjector() { + return injector + } + } + restServer.start() + contextListener.contextInitialized( + new ServletContextEvent((restServer.handler as ServletContextHandler).servletContext)) + try { + restServer.join() + } catch (InterruptedException ignored) { + Thread.currentThread().interrupt() + } + } + + protected void mockTargetServerResponse(String url, String responseBody, int delayMilliseconds=0) { + def response = WireMock.aResponse().withStatus(200) + .withBody(responseBody) + .withHeader('Content-Type', 'text/plain') + .withFixedDelay(delayMilliseconds) + WireMock.stubFor(WireMock.get(WireMock.urlEqualTo("/${url}")).willReturn(response)) + } +} diff --git a/browserup-proxy-rest-clients/src/test/ruby/.rspec b/browserup-proxy-rest-clients/src/test/ruby/.rspec new file mode 100644 index 000000000..75a19da78 --- /dev/null +++ b/browserup-proxy-rest-clients/src/test/ruby/.rspec @@ -0,0 +1,3 @@ +--color +--format documentation +--fail-fast \ No newline at end of file diff --git a/browserup-proxy-rest-clients/src/test/ruby/Gemfile b/browserup-proxy-rest-clients/src/test/ruby/Gemfile new file mode 100644 index 000000000..0d2d0eb9f --- /dev/null +++ b/browserup-proxy-rest-clients/src/test/ruby/Gemfile @@ -0,0 +1,4 @@ +source 'https://rubygems.org' + +gem 'openapi_client', '~> 1.0.0' +gem 'rspec' diff --git a/browserup-proxy-rest-clients/src/test/ruby/Gemfile.lock b/browserup-proxy-rest-clients/src/test/ruby/Gemfile.lock new file mode 100644 index 000000000..2653af138 --- /dev/null +++ b/browserup-proxy-rest-clients/src/test/ruby/Gemfile.lock @@ -0,0 +1,36 @@ +GEM + remote: https://rubygems.org/ + specs: + diff-lcs (1.3) + ethon (0.12.0) + ffi (>= 1.3.0) + ffi (1.11.1) + json (2.2.0) + openapi_client (1.0.0) + json (~> 2.1, >= 2.1.0) + typhoeus (~> 1.0, >= 1.0.1) + rspec (3.8.0) + rspec-core (~> 3.8.0) + rspec-expectations (~> 3.8.0) + rspec-mocks (~> 3.8.0) + rspec-core (3.8.0) + rspec-support (~> 3.8.0) + rspec-expectations (3.8.1) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.8.0) + rspec-mocks (3.8.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.8.0) + rspec-support (3.8.0) + typhoeus (1.3.1) + ethon (>= 0.9.0) + +PLATFORMS + ruby + +DEPENDENCIES + openapi_client (~> 1.0.0) + rspec + +BUNDLED WITH + 1.15.3 diff --git a/browserup-proxy-rest-clients/src/test/ruby/spec/test_client_spec.rb b/browserup-proxy-rest-clients/src/test/ruby/spec/test_client_spec.rb new file mode 100644 index 000000000..ab5650f36 --- /dev/null +++ b/browserup-proxy-rest-clients/src/test/ruby/spec/test_client_spec.rb @@ -0,0 +1,16 @@ +require 'openapi_client' + +describe OpenapiClient do + it 'connects to api' do + api_instance = OpenapiClient::DefaultApi.new + api_instance.api_client.config.host = 'localhost:35629' + port = 8081 + url_pattern = '^.*$' + + begin + p api_instance.entries(port, url_pattern) + rescue OpenapiClient::ApiError => e + puts "Exception when calling DefaultApi->entries: #{e}" + end + end +end \ No newline at end of file diff --git a/browserup-proxy-rest/build.gradle b/browserup-proxy-rest/build.gradle index ae5dfeb0e..cd458c4f8 100644 --- a/browserup-proxy-rest/build.gradle +++ b/browserup-proxy-rest/build.gradle @@ -106,3 +106,15 @@ dependencies { testImplementation 'org.awaitility:awaitility:4.0.2' testImplementation 'com.github.tomakehurst:wiremock-jre8:2.24.1' } + +task createVersionProperties() { + doLast { + new File("$buildDir/resources/main/browserup-proxy-rest-version.properties").withWriter { w -> + Properties p = new Properties() + p['version'] = project.version.toString() + p.store w, null + } + } +} + +build.finalizedBy(createVersionProperties) diff --git a/browserup-proxy-rest/src/main/java/com/browserup/bup/rest/resource/entries/EntriesProxyResource.java b/browserup-proxy-rest/src/main/java/com/browserup/bup/rest/resource/entries/EntriesProxyResource.java index 114234afa..b783eda76 100644 --- a/browserup-proxy-rest/src/main/java/com/browserup/bup/rest/resource/entries/EntriesProxyResource.java +++ b/browserup-proxy-rest/src/main/java/com/browserup/bup/rest/resource/entries/EntriesProxyResource.java @@ -13,9 +13,11 @@ import com.browserup.bup.rest.validation.PortWithExistingProxyConstraint; import com.browserup.bup.util.HttpStatusClass; import com.browserup.harreader.model.HarEntry; +import io.swagger.v3.oas.annotations.OpenAPIDefinition; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.enums.ParameterIn; +import io.swagger.v3.oas.annotations.info.Info; import io.swagger.v3.oas.annotations.media.ArraySchema; import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.media.Schema; @@ -35,6 +37,11 @@ import static com.browserup.bup.rest.swagger.DocConstants.*; +@OpenAPIDefinition( + info = @Info( + version = "" + ) +) @Path("/proxy/{port}/har/entries") public class EntriesProxyResource { private static final String URL_PATTERN = "urlPattern"; diff --git a/browserup-proxy-rest/src/main/java/com/browserup/bup/rest/swagger/CustomOpenApiReader.java b/browserup-proxy-rest/src/main/java/com/browserup/bup/rest/swagger/CustomOpenApiReader.java index 5d5ca6d8f..bd078c2c2 100644 --- a/browserup-proxy-rest/src/main/java/com/browserup/bup/rest/swagger/CustomOpenApiReader.java +++ b/browserup-proxy-rest/src/main/java/com/browserup/bup/rest/swagger/CustomOpenApiReader.java @@ -4,8 +4,6 @@ import com.fasterxml.jackson.databind.introspect.AnnotatedMethod; import io.swagger.v3.jaxrs2.Reader; import io.swagger.v3.oas.annotations.responses.ApiResponse; -import io.swagger.v3.oas.integration.api.OpenAPIConfiguration; -import io.swagger.v3.oas.integration.api.OpenApiReader; import io.swagger.v3.oas.models.ExternalDocumentation; import io.swagger.v3.oas.models.OpenAPI; import io.swagger.v3.oas.models.Operation; @@ -15,14 +13,29 @@ import io.swagger.v3.oas.models.security.SecurityRequirement; import io.swagger.v3.oas.models.servers.Server; import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import javax.ws.rs.Consumes; import javax.ws.rs.Path; import javax.ws.rs.Produces; +import java.io.IOException; +import java.io.InputStream; import java.lang.reflect.Method; import java.util.*; +/** + * Customizes generation of the following OpenAPI data: + * - OperationID: generates operation id using scheme: {last URL path element of resource}{resource method} + * - Info version: uses version properties file generated while gradle build to get current version of the project + */ public class CustomOpenApiReader extends Reader { + private static final String VERSION_PROPERTIES_FILE_NAME = "browserup-proxy-rest-version.properties"; + private static final String DEFAULT_VERSION = "2.0.0"; + private static final Logger LOG = LoggerFactory.getLogger(CustomOpenApiReader.class); + + private static String version; + @Override protected String getOperationId(String operationId) { return super.getOperationId(operationId); @@ -48,6 +61,13 @@ public Operation parseMethod(Method method, List globalParameters, Pr return operation; } + @Override + public OpenAPI read(Class cls, String parentPath, String parentMethod, boolean isSubresource, RequestBody parentRequestBody, ApiResponses parentResponses, Set parentTags, List parentParameters, Set> scannedResources) { + OpenAPI result = super.read(cls, parentPath, parentMethod, isSubresource, parentRequestBody, parentResponses, parentTags, parentParameters, scannedResources); + result.getInfo().setVersion(getVersion()); + return result; + } + private Optional createOperationIdPrefixByPathAnnotation(String pathAnnoValue) { String[] pathElements = pathAnnoValue.split("/"); if (pathElements.length > 0) { @@ -55,4 +75,41 @@ private Optional createOperationIdPrefixByPathAnnotation(String pathAnno } return Optional.empty(); } + + private String getVersion() { + if (version == null) { + synchronized (CustomOpenApiReader.class) { + if (version == null) { + version = readVersion().orElse(DEFAULT_VERSION); + } + } + } + return version; + } + + private Optional readVersion() { + InputStream in = CustomOpenApiReader.class.getClassLoader().getResourceAsStream(VERSION_PROPERTIES_FILE_NAME); + if (in == null) { + LOG.warn("Couldn't read version properties, resource not found by path: " + VERSION_PROPERTIES_FILE_NAME); + return Optional.empty(); + } + + Properties properties = new Properties(); + try { + properties.load(in); + Object version = properties.get("version"); + if (version == null) { + LOG.warn("Couldn't read version properties (version is null)"); + } else if (!(version instanceof String)) { + LOG.warn("Couldn't read version properties (version is not String)"); + } else if (StringUtils.isEmpty((CharSequence) version)) { + LOG.warn("Couldn't read version properties (version is empty)"); + } else { + return Optional.of((String) version); + } + } catch (IOException e) { + LOG.warn("Couldn't read version properties", e); + } + return Optional.empty(); + } } diff --git a/build.gradle b/build.gradle index 5c8419c53..6beeb6bf7 100644 --- a/build.gradle +++ b/build.gradle @@ -21,6 +21,10 @@ configurations.all { } } +ext { + jerseyVersion = '2.29' +} + subprojects { apply plugin: 'java' apply plugin: 'idea' @@ -71,4 +75,4 @@ subprojects { sign configurations.archives } } -} +} \ No newline at end of file From cd2b4ae0d0c53a90833cb900cdd5f965285b58cc Mon Sep 17 00:00:00 2001 From: "kirill.turutin" Date: Mon, 5 Aug 2019 12:43:53 +0300 Subject: [PATCH 03/12] Ruby client integration test --- browserup-proxy-rest-clients/build.gradle | 18 ++-- .../java/com/CustomRubyClientCodegen.java | 9 ++ .../groovy/com/FindHarEntriesRestTest.groovy | 89 ------------------- .../bup}/WithRunningProxyRestTest.groovy | 4 +- .../browserup/bup/ruby/RubyClientTest.groovy | 61 +++++++++++++ .../src/test/ruby/.gitignore | 1 + .../src/test/ruby/.rspec | 4 +- .../src/test/ruby/Dockerfile | 20 +++++ .../src/test/ruby/Gemfile | 9 +- .../src/test/ruby/Gemfile.lock | 38 +++++++- .../src/test/ruby/spec/test_client_spec.rb | 17 +++- 11 files changed, 162 insertions(+), 108 deletions(-) create mode 100644 browserup-proxy-rest-clients/src/main/java/com/CustomRubyClientCodegen.java delete mode 100644 browserup-proxy-rest-clients/src/test/groovy/com/FindHarEntriesRestTest.groovy rename browserup-proxy-rest-clients/src/test/groovy/com/{ => browserup/bup}/WithRunningProxyRestTest.groovy (98%) create mode 100644 browserup-proxy-rest-clients/src/test/groovy/com/browserup/bup/ruby/RubyClientTest.groovy create mode 100644 browserup-proxy-rest-clients/src/test/ruby/.gitignore create mode 100644 browserup-proxy-rest-clients/src/test/ruby/Dockerfile diff --git a/browserup-proxy-rest-clients/build.gradle b/browserup-proxy-rest-clients/build.gradle index ed516ef57..611376473 100644 --- a/browserup-proxy-rest-clients/build.gradle +++ b/browserup-proxy-rest-clients/build.gradle @@ -6,7 +6,7 @@ plugins { id 'java-library' id 'groovy' id "io.swagger.core.v3.swagger-gradle-plugin" version "2.0.8" - id "org.openapi.generator" version "4.0.0-beta3" + id "org.openapi.generator" version "4.0.3" } resolve { @@ -21,9 +21,9 @@ resolve { } def clientLanguages = [ - 'JavaScript', - 'Ruby', - 'Python' + //'JavaScript', + 'Ruby' + //'Python' ] clientLanguages.each { lang -> @@ -49,6 +49,11 @@ task openApiGenerateClients() { clientLanguages.each { lang -> dependsOn "openApiGenerate${lang}Client" } + + copy { + from "$buildDir/swagger-clients/ruby/" + into "src/test/ruby/client" + } } archivesBaseName = 'browserup-proxy-rest-clients' @@ -61,7 +66,8 @@ dependencies { implementation 'com.google.inject.extensions:guice-servlet:4.2.2' implementation 'com.google.inject.extensions:guice-multibindings:4.2.2' implementation 'com.google.sitebricks:sitebricks:0.8.11' - + implementation 'org.openapitools:openapi-generator:4.0.3' + testImplementation project(':browserup-proxy-mitm') testImplementation 'junit:junit:4.12' @@ -77,6 +83,8 @@ dependencies { testImplementation 'org.awaitility:awaitility:3.1.6' testImplementation 'xyz.rogfam:littleproxy:2.0.0-beta-3' testImplementation 'com.github.tomakehurst:wiremock-jre8:2.24.0' + testImplementation 'org.testcontainers:testcontainers:1.12.0' + } diff --git a/browserup-proxy-rest-clients/src/main/java/com/CustomRubyClientCodegen.java b/browserup-proxy-rest-clients/src/main/java/com/CustomRubyClientCodegen.java new file mode 100644 index 000000000..df6e98be1 --- /dev/null +++ b/browserup-proxy-rest-clients/src/main/java/com/CustomRubyClientCodegen.java @@ -0,0 +1,9 @@ +package com; + +import org.openapitools.codegen.languages.RubyClientCodegen; + +public class CustomRubyClientCodegen extends RubyClientCodegen { + public CustomRubyClientCodegen() { + reservedWords.add("send"); + } +} diff --git a/browserup-proxy-rest-clients/src/test/groovy/com/FindHarEntriesRestTest.groovy b/browserup-proxy-rest-clients/src/test/groovy/com/FindHarEntriesRestTest.groovy deleted file mode 100644 index 5ba4432d0..000000000 --- a/browserup-proxy-rest-clients/src/test/groovy/com/FindHarEntriesRestTest.groovy +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Modifications Copyright (c) 2019 BrowserUp, Inc. - */ - -package com - -import com.browserup.harreader.model.HarEntry -import com.fasterxml.jackson.databind.ObjectMapper -import com.github.tomakehurst.wiremock.client.WireMock -import groovyx.net.http.HttpResponseDecorator -import groovyx.net.http.Method -import org.apache.http.entity.ContentType -import org.hamcrest.Matchers -import org.junit.Test - -import static com.github.tomakehurst.wiremock.client.WireMock.getRequestedFor -import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo -import static org.junit.Assert.assertEquals -import static org.junit.Assert.assertThat - -class FindHarEntriesRestTest extends WithRunningProxyRestTest { - - @Override - String getUrlPath() { - return 'har/entries' - } - - @Test - void findHarEntryByUrlPattern() { - def urlToCatch = 'test' - def urlNotToCatch = 'missing' - def responseBody = 'success' - - mockTargetServerResponse(urlToCatch, responseBody) - mockTargetServerResponse(urlNotToCatch, responseBody) - - proxyManager.get()[0].newHar() - - requestToTargetServer(urlToCatch, responseBody) - requestToTargetServer(urlNotToCatch, responseBody) - - proxyRestServerClient.request(Method.GET, ContentType.APPLICATION_JSON) { req -> - def urlPattern = ".*${urlToCatch}" - uri.path = "/proxy/${proxy.port}/${urlPath}" - uri.query = [urlPattern: urlPattern] - response.success = { HttpResponseDecorator resp -> - HarEntry[] entries = new ObjectMapper().readValue(resp.entity.content, HarEntry[]) as HarEntry[] - assertThat('Expected to find only one entry', entries, Matchers.arrayWithSize(1)) - assertThat('Expected to find entry containing url from url filter pattern', - entries[0].request.url, Matchers.containsString(urlToCatch)) - assertThat('Expected to find no entries with urlNotToCatch filter', - entries[0].request.url, Matchers.not(Matchers.containsString(urlNotToCatch))) - } - } - - WireMock.verify(1, getRequestedFor(urlEqualTo("/${urlToCatch}"))) - WireMock.verify(1, getRequestedFor(urlEqualTo("/${urlNotToCatch}"))) - } - - @Test - void getEmptyEntriesArrayIfNoEntriesFoundByUrl() { - def urlToCatch = 'test' - def urlNotToCatch = 'missing' - def responseBody = 'success' - - mockTargetServerResponse(urlNotToCatch, responseBody) - - proxyManager.get()[0].newHar() - - targetServerClient.request(Method.GET, ContentType.WILDCARD) { req -> - uri.path = "/${urlNotToCatch}" - response.success = { _, reader -> - assertEquals(responseBody, reader.text) - } - } - - proxyRestServerClient.request(Method.GET, ContentType.APPLICATION_JSON) { req -> - def urlPattern = ".*${urlToCatch}" - uri.path = "/proxy/${proxy.port}/${urlPath}" - uri.query = [urlPattern: urlPattern] - response.success = { HttpResponseDecorator resp -> - HarEntry[] entries = new ObjectMapper().readValue(resp.entity.content, HarEntry[]) as HarEntry[] - assertThat('Expected get empty har entries array', entries, Matchers.arrayWithSize(0)) - } - } - - WireMock.verify(1, getRequestedFor(urlEqualTo("/${urlNotToCatch}"))) - } -} diff --git a/browserup-proxy-rest-clients/src/test/groovy/com/WithRunningProxyRestTest.groovy b/browserup-proxy-rest-clients/src/test/groovy/com/browserup/bup/WithRunningProxyRestTest.groovy similarity index 98% rename from browserup-proxy-rest-clients/src/test/groovy/com/WithRunningProxyRestTest.groovy rename to browserup-proxy-rest-clients/src/test/groovy/com/browserup/bup/WithRunningProxyRestTest.groovy index 7dc6eeac2..38d8dbffd 100644 --- a/browserup-proxy-rest-clients/src/test/groovy/com/WithRunningProxyRestTest.groovy +++ b/browserup-proxy-rest-clients/src/test/groovy/com/browserup/bup/WithRunningProxyRestTest.groovy @@ -2,7 +2,7 @@ * Modifications Copyright (c) 2019 BrowserUp, Inc. */ -package com +package com.browserup.bup import com.browserup.bup.BrowserUpProxyServer import com.browserup.bup.proxy.ProxyManager @@ -34,7 +34,7 @@ import javax.servlet.ServletContextEvent import java.util.concurrent.TimeUnit abstract class WithRunningProxyRestTest { - private static final Logger LOG = LoggerFactory.getLogger(ProxyManager) + private static final Logger LOG = LoggerFactory.getLogger(WithRunningProxyRestTest) protected ProxyManager proxyManager protected BrowserUpProxyServer proxy diff --git a/browserup-proxy-rest-clients/src/test/groovy/com/browserup/bup/ruby/RubyClientTest.groovy b/browserup-proxy-rest-clients/src/test/groovy/com/browserup/bup/ruby/RubyClientTest.groovy new file mode 100644 index 000000000..411742505 --- /dev/null +++ b/browserup-proxy-rest-clients/src/test/groovy/com/browserup/bup/ruby/RubyClientTest.groovy @@ -0,0 +1,61 @@ +/* + * Modifications Copyright (c) 2019 BrowserUp, Inc. + */ + +package com.browserup.bup.ruby + +import com.browserup.bup.WithRunningProxyRestTest +import org.awaitility.Awaitility +import org.junit.Assert +import org.junit.Test +import org.slf4j.Logger +import org.slf4j.LoggerFactory +import org.testcontainers.Testcontainers +import org.testcontainers.containers.GenericContainer +import org.testcontainers.images.builder.ImageFromDockerfile + +import java.nio.file.Path +import java.util.concurrent.TimeUnit + +class RubyClientTest extends WithRunningProxyRestTest { + private static final Logger LOG = LoggerFactory.getLogger(RubyClientTest) + + @Override + String getUrlPath() { + return 'har/entries' + } + + @Test + void connectToProxy() { + def urlToCatch = 'test' + def urlNotToCatch = 'missing' + def responseBody = 'success' + + mockTargetServerResponse(urlToCatch, responseBody) + mockTargetServerResponse(urlNotToCatch, responseBody) + + proxyManager.get()[0].newHar() + + requestToTargetServer(urlToCatch, responseBody) + requestToTargetServer(urlNotToCatch, responseBody) + + Testcontainers.exposeHostPorts(restServer.connectors[0].localPort as Integer) + Testcontainers.exposeHostPorts(proxy.port as Integer) + + def dockerfile = new File('./src/test/ruby/Dockerfile') + def container = new GenericContainer( + new ImageFromDockerfile() + .withDockerfile(Path.of(dockerfile.path))) + .withEnv('PROXY_REST_HOST', 'host.testcontainers.internal') + .withEnv('PROXY_REST_PORT', restServer.connectors[0].localPort as String) + .withEnv('PROXY_PORT', proxy.port as String) + + container.start() + + Awaitility.await().atMost(10, TimeUnit.SECONDS).until({-> !container.isRunning()}) + + LOG.info('Docker log: ' + container.getLogs()) + + Assert.assertEquals("Expected ruby-client container exit code to be 0", 0, container.getCurrentContainerInfo().getState().getExitCode()) + } +} diff --git a/browserup-proxy-rest-clients/src/test/ruby/.gitignore b/browserup-proxy-rest-clients/src/test/ruby/.gitignore new file mode 100644 index 000000000..7f269dec1 --- /dev/null +++ b/browserup-proxy-rest-clients/src/test/ruby/.gitignore @@ -0,0 +1 @@ +client/ \ No newline at end of file diff --git a/browserup-proxy-rest-clients/src/test/ruby/.rspec b/browserup-proxy-rest-clients/src/test/ruby/.rspec index 75a19da78..5052887a0 100644 --- a/browserup-proxy-rest-clients/src/test/ruby/.rspec +++ b/browserup-proxy-rest-clients/src/test/ruby/.rspec @@ -1,3 +1 @@ ---color ---format documentation ---fail-fast \ No newline at end of file +--color \ No newline at end of file diff --git a/browserup-proxy-rest-clients/src/test/ruby/Dockerfile b/browserup-proxy-rest-clients/src/test/ruby/Dockerfile new file mode 100644 index 000000000..66d1ffce6 --- /dev/null +++ b/browserup-proxy-rest-clients/src/test/ruby/Dockerfile @@ -0,0 +1,20 @@ +FROM ruby:2.5 + +RUN bundle config --global frozen 1 + +WORKDIR / + +COPY client/ /ruby-client/ + +# Build ruby client gem, install locally +WORKDIR /ruby-client/ +RUN gem build openapi_client.gemspec +RUN gem install ./openapi_client-1.0.0.gem + +COPY . /ruby/ +WORKDIR /ruby/ + +RUN bundle config --delete frozen +RUN bundle install + +CMD ["bundle", "exec", "rspec", "--backtrace"] \ No newline at end of file diff --git a/browserup-proxy-rest-clients/src/test/ruby/Gemfile b/browserup-proxy-rest-clients/src/test/ruby/Gemfile index 0d2d0eb9f..6ec050d94 100644 --- a/browserup-proxy-rest-clients/src/test/ruby/Gemfile +++ b/browserup-proxy-rest-clients/src/test/ruby/Gemfile @@ -1,4 +1,9 @@ source 'https://rubygems.org' -gem 'openapi_client', '~> 1.0.0' -gem 'rspec' +group :development, :test do + gem 'rake', '~> 12.0.0' + gem 'pry-byebug' + gem 'rspec' + gem 'rubocop', '~> 0.66.0' + gem 'openapi_client', '~> 1.0.0' +end diff --git a/browserup-proxy-rest-clients/src/test/ruby/Gemfile.lock b/browserup-proxy-rest-clients/src/test/ruby/Gemfile.lock index 2653af138..2ac5a88b3 100644 --- a/browserup-proxy-rest-clients/src/test/ruby/Gemfile.lock +++ b/browserup-proxy-rest-clients/src/test/ruby/Gemfile.lock @@ -1,36 +1,66 @@ GEM remote: https://rubygems.org/ specs: + ast (2.4.0) + byebug (11.0.1) + coderay (1.1.2) diff-lcs (1.3) ethon (0.12.0) ffi (>= 1.3.0) ffi (1.11.1) + jaro_winkler (1.5.3) json (2.2.0) + method_source (0.9.2) openapi_client (1.0.0) json (~> 2.1, >= 2.1.0) typhoeus (~> 1.0, >= 1.0.1) + parallel (1.17.0) + parser (2.6.3.0) + ast (~> 2.4.0) + pry (0.12.2) + coderay (~> 1.1.0) + method_source (~> 0.9.0) + pry-byebug (3.7.0) + byebug (~> 11.0) + pry (~> 0.10) + psych (3.1.0) + rainbow (3.0.0) + rake (12.0.0) rspec (3.8.0) rspec-core (~> 3.8.0) rspec-expectations (~> 3.8.0) rspec-mocks (~> 3.8.0) - rspec-core (3.8.0) + rspec-core (3.8.2) rspec-support (~> 3.8.0) - rspec-expectations (3.8.1) + rspec-expectations (3.8.4) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.8.0) - rspec-mocks (3.8.0) + rspec-mocks (3.8.1) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.8.0) - rspec-support (3.8.0) + rspec-support (3.8.2) + rubocop (0.66.0) + jaro_winkler (~> 1.5.1) + parallel (~> 1.10) + parser (>= 2.5, != 2.5.1.1) + psych (>= 3.1.0) + rainbow (>= 2.2.2, < 4.0) + ruby-progressbar (~> 1.7) + unicode-display_width (>= 1.4.0, < 1.6) + ruby-progressbar (1.10.1) typhoeus (1.3.1) ethon (>= 0.9.0) + unicode-display_width (1.5.0) PLATFORMS ruby DEPENDENCIES openapi_client (~> 1.0.0) + pry-byebug + rake (~> 12.0.0) rspec + rubocop (~> 0.66.0) BUNDLED WITH 1.15.3 diff --git a/browserup-proxy-rest-clients/src/test/ruby/spec/test_client_spec.rb b/browserup-proxy-rest-clients/src/test/ruby/spec/test_client_spec.rb index ab5650f36..e69618e05 100644 --- a/browserup-proxy-rest-clients/src/test/ruby/spec/test_client_spec.rb +++ b/browserup-proxy-rest-clients/src/test/ruby/spec/test_client_spec.rb @@ -2,15 +2,26 @@ describe OpenapiClient do it 'connects to api' do + proxy_rest_host = ENV["PROXY_REST_HOST"] + proxy_rest_port = ENV["PROXY_REST_PORT"] + proxy_port = ENV["PROXY_PORT"] + + p "Using the following env variables:" + p "PROXY_REST_HOST = #{proxy_rest_host}" + p "PROXY_REST_PORT = #{proxy_rest_port}" + p "PROXY_PORT = #{proxy_port}" + api_instance = OpenapiClient::DefaultApi.new - api_instance.api_client.config.host = 'localhost:35629' - port = 8081 + api_instance.api_client.config.host = "#{proxy_rest_host}:#{proxy_rest_port}" + port = proxy_port url_pattern = '^.*$' begin - p api_instance.entries(port, url_pattern) + entries_response = api_instance.entries(port, url_pattern).to_json + p "Got the following entries in the response: #{entries_response}" rescue OpenapiClient::ApiError => e puts "Exception when calling DefaultApi->entries: #{e}" + raise end end end \ No newline at end of file From e4af520a9a28e5441a79e83d64b52b67e44c9a09 Mon Sep 17 00:00:00 2001 From: "kirill.turutin" Date: Tue, 6 Aug 2019 12:02:14 +0300 Subject: [PATCH 04/12] Remarks --- browserup-proxy-rest-clients/build.gradle | 16 ++++++++++------ .../{swagger-config.json => openapi-config.json} | 0 .../bup/proxy/guice/JettyServerProvider.java | 8 ++++---- .../CustomOpenApiReader.java | 2 +- .../rest/{swagger => openapi}/DocConstants.java | 2 +- .../resource/entries/EntriesProxyResource.java | 2 +- .../mostrecent/MostRecentEntryProxyResource.java | 3 +-- .../src/main/resources/swagger-config.yaml | 2 +- 8 files changed, 19 insertions(+), 16 deletions(-) rename browserup-proxy-rest-clients/src/main/resources/{swagger-config.json => openapi-config.json} (100%) rename browserup-proxy-rest/src/main/java/com/browserup/bup/rest/{swagger => openapi}/CustomOpenApiReader.java (99%) rename browserup-proxy-rest/src/main/java/com/browserup/bup/rest/{swagger => openapi}/DocConstants.java (98%) diff --git a/browserup-proxy-rest-clients/build.gradle b/browserup-proxy-rest-clients/build.gradle index 611376473..bf6a1f5d7 100644 --- a/browserup-proxy-rest-clients/build.gradle +++ b/browserup-proxy-rest-clients/build.gradle @@ -13,11 +13,11 @@ resolve { outputFileName = 'openapi' outputFormat = 'YAML' prettyPrint = 'TRUE' - openApiFile = file("src/main/resources/swagger-config.json") + openApiFile = file("src/main/resources/openapi-config.json") classpath = sourceSets.main.runtimeClasspath - readerClass = "com.browserup.bup.rest.swagger.CustomOpenApiReader" + readerClass = "com.browserup.bup.rest.openapi.CustomOpenApiReader" resourcePackages = ['com.browserup.bup.rest.resource'] - outputPath = 'build/swagger' + outputPath = 'build/openapi' } def clientLanguages = [ @@ -31,8 +31,8 @@ clientLanguages.each { lang -> dependsOn 'resolve' def language = lang.toLowerCase() generatorName = language - inputSpec = "$buildDir/swagger/openapi.yaml".toString() - outputDir = "$buildDir/swagger-clients/$language/".toString() + inputSpec = "$buildDir/openapi/openapi.yaml".toString() + outputDir = "$buildDir/openapi-clients/$language/".toString() apiPackage = 'com.browserup.bup.rest' invokerPackage = 'com.browserup.bup.rest.client.invoker' modelPackage = 'com.browserup.bup.rest.client.model' @@ -51,9 +51,13 @@ task openApiGenerateClients() { } copy { - from "$buildDir/swagger-clients/ruby/" + from "$buildDir/openapi-clients/ruby/" into "src/test/ruby/client" } + + doLast { + project.delete "$buildDir/openapi-clients" + } } archivesBaseName = 'browserup-proxy-rest-clients' diff --git a/browserup-proxy-rest-clients/src/main/resources/swagger-config.json b/browserup-proxy-rest-clients/src/main/resources/openapi-config.json similarity index 100% rename from browserup-proxy-rest-clients/src/main/resources/swagger-config.json rename to browserup-proxy-rest-clients/src/main/resources/openapi-config.json diff --git a/browserup-proxy-rest/src/main/java/com/browserup/bup/proxy/guice/JettyServerProvider.java b/browserup-proxy-rest/src/main/java/com/browserup/bup/proxy/guice/JettyServerProvider.java index 4afe18ba6..7f5b2919d 100644 --- a/browserup-proxy-rest/src/main/java/com/browserup/bup/proxy/guice/JettyServerProvider.java +++ b/browserup-proxy-rest/src/main/java/com/browserup/bup/proxy/guice/JettyServerProvider.java @@ -33,18 +33,18 @@ import javax.servlet.DispatcherType; public class JettyServerProvider implements Provider { - public static final String SWAGGER_CONFIG_NAME = "swagger-config.yaml"; - public static final String SWAGGER_PACKAGE = "com.browserup.bup.rest.resource"; + public static final String OPENAPI_CONFIG_YAML = "openapi-config.yaml"; + public static final String OPENAPI_PACKAGE = "com.browserup.bup.rest.resource"; private Server server; @Inject public JettyServerProvider(@Named("port") int port, @Named("address") String address, MitmProxyManager proxyManager) throws UnknownHostException { OpenApiResource openApiResource = new OpenApiResource(); - openApiResource.setConfigLocation(SWAGGER_CONFIG_NAME); + openApiResource.setConfigLocation(OPENAPI_CONFIG_YAML); ResourceConfig resourceConfig = new ResourceConfig(); - resourceConfig.packages(SWAGGER_PACKAGE); + resourceConfig.packages(OPENAPI_PACKAGE); resourceConfig.register(openApiResource); resourceConfig.register(proxyManagerToHkBinder(proxyManager)); resourceConfig.register(JacksonFeature.class); diff --git a/browserup-proxy-rest/src/main/java/com/browserup/bup/rest/swagger/CustomOpenApiReader.java b/browserup-proxy-rest/src/main/java/com/browserup/bup/rest/openapi/CustomOpenApiReader.java similarity index 99% rename from browserup-proxy-rest/src/main/java/com/browserup/bup/rest/swagger/CustomOpenApiReader.java rename to browserup-proxy-rest/src/main/java/com/browserup/bup/rest/openapi/CustomOpenApiReader.java index bd078c2c2..a0a58bd8f 100644 --- a/browserup-proxy-rest/src/main/java/com/browserup/bup/rest/swagger/CustomOpenApiReader.java +++ b/browserup-proxy-rest/src/main/java/com/browserup/bup/rest/openapi/CustomOpenApiReader.java @@ -1,4 +1,4 @@ -package com.browserup.bup.rest.swagger; +package com.browserup.bup.rest.openapi; import com.fasterxml.jackson.annotation.JsonView; import com.fasterxml.jackson.databind.introspect.AnnotatedMethod; diff --git a/browserup-proxy-rest/src/main/java/com/browserup/bup/rest/swagger/DocConstants.java b/browserup-proxy-rest/src/main/java/com/browserup/bup/rest/openapi/DocConstants.java similarity index 98% rename from browserup-proxy-rest/src/main/java/com/browserup/bup/rest/swagger/DocConstants.java rename to browserup-proxy-rest/src/main/java/com/browserup/bup/rest/openapi/DocConstants.java index d2a9f99da..034e734ea 100644 --- a/browserup-proxy-rest/src/main/java/com/browserup/bup/rest/swagger/DocConstants.java +++ b/browserup-proxy-rest/src/main/java/com/browserup/bup/rest/openapi/DocConstants.java @@ -1,4 +1,4 @@ -package com.browserup.bup.rest.swagger; +package com.browserup.bup.rest.openapi; public class DocConstants { public static final String STATUS_DESCRIPTION = "Http status."; diff --git a/browserup-proxy-rest/src/main/java/com/browserup/bup/rest/resource/entries/EntriesProxyResource.java b/browserup-proxy-rest/src/main/java/com/browserup/bup/rest/resource/entries/EntriesProxyResource.java index b783eda76..c8a6a436d 100644 --- a/browserup-proxy-rest/src/main/java/com/browserup/bup/rest/resource/entries/EntriesProxyResource.java +++ b/browserup-proxy-rest/src/main/java/com/browserup/bup/rest/resource/entries/EntriesProxyResource.java @@ -35,7 +35,7 @@ import java.util.Collection; import java.util.regex.Pattern; -import static com.browserup.bup.rest.swagger.DocConstants.*; +import static com.browserup.bup.rest.openapi.DocConstants.*; @OpenAPIDefinition( info = @Info( diff --git a/browserup-proxy-rest/src/main/java/com/browserup/bup/rest/resource/mostrecent/MostRecentEntryProxyResource.java b/browserup-proxy-rest/src/main/java/com/browserup/bup/rest/resource/mostrecent/MostRecentEntryProxyResource.java index d0e513bc0..0d5e6b49e 100644 --- a/browserup-proxy-rest/src/main/java/com/browserup/bup/rest/resource/mostrecent/MostRecentEntryProxyResource.java +++ b/browserup-proxy-rest/src/main/java/com/browserup/bup/rest/resource/mostrecent/MostRecentEntryProxyResource.java @@ -27,10 +27,9 @@ import javax.ws.rs.QueryParam; import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; import java.util.regex.Pattern; -import static com.browserup.bup.rest.swagger.DocConstants.*; +import static com.browserup.bup.rest.openapi.DocConstants.*; @Path("/proxy/{port}/har/mostRecentEntry") public class MostRecentEntryProxyResource { diff --git a/browserup-proxy-rest/src/main/resources/swagger-config.yaml b/browserup-proxy-rest/src/main/resources/swagger-config.yaml index 22c4d700a..8a0fdbfc7 100644 --- a/browserup-proxy-rest/src/main/resources/swagger-config.yaml +++ b/browserup-proxy-rest/src/main/resources/swagger-config.yaml @@ -1,7 +1,7 @@ resourcePackages: - com.browserup.bup.rest.resource prettyPrint: true -readerClass: com.browserup.bup.rest.swagger.CustomOpenApiReader +readerClass: com.browserup.bup.rest.openapi.CustomOpenApiReader cacheTTL: 0 openAPI: info: From 6b1e35efcf5885e0b81aea9c9a05329c5aa0a31d Mon Sep 17 00:00:00 2001 From: "kirill.turutin" Date: Wed, 7 Aug 2019 16:07:16 +0300 Subject: [PATCH 05/12] python client --- browserup-proxy-rest-clients/build.gradle | 32 ++++-- .../bup/python/PythonTestClient.groovy | 106 ++++++++++++++++++ .../browserup/bup/ruby/RubyClientTest.groovy | 48 +++++++- .../src/test/python/.gitignore | 1 + .../src/test/python/Dockerfile | 17 +++ .../src/test/python/test/python_test.py | 22 ++++ settings.gradle | 21 ++++ 7 files changed, 234 insertions(+), 13 deletions(-) create mode 100644 browserup-proxy-rest-clients/src/test/groovy/com/browserup/bup/python/PythonTestClient.groovy create mode 100644 browserup-proxy-rest-clients/src/test/python/.gitignore create mode 100644 browserup-proxy-rest-clients/src/test/python/Dockerfile create mode 100644 browserup-proxy-rest-clients/src/test/python/test/python_test.py diff --git a/browserup-proxy-rest-clients/build.gradle b/browserup-proxy-rest-clients/build.gradle index bf6a1f5d7..b59a86183 100644 --- a/browserup-proxy-rest-clients/build.gradle +++ b/browserup-proxy-rest-clients/build.gradle @@ -6,7 +6,7 @@ plugins { id 'java-library' id 'groovy' id "io.swagger.core.v3.swagger-gradle-plugin" version "2.0.8" - id "org.openapi.generator" version "4.0.3" + id 'org.openapi.generator' version '4.1.0-SNAPSHOT' } resolve { @@ -22,8 +22,8 @@ resolve { def clientLanguages = [ //'JavaScript', - 'Ruby' - //'Python' + 'Ruby', + 'Python' ] clientLanguages.each { lang -> @@ -33,9 +33,9 @@ clientLanguages.each { lang -> generatorName = language inputSpec = "$buildDir/openapi/openapi.yaml".toString() outputDir = "$buildDir/openapi-clients/$language/".toString() - apiPackage = 'com.browserup.bup.rest' - invokerPackage = 'com.browserup.bup.rest.client.invoker' - modelPackage = 'com.browserup.bup.rest.client.model' +// apiPackage = "api" +// invokerPackage = "invoker" +// modelPackage = "model" systemProperties = [ modelDocs: 'false' ] @@ -50,12 +50,19 @@ task openApiGenerateClients() { dependsOn "openApiGenerate${lang}Client" } - copy { - from "$buildDir/openapi-clients/ruby/" - into "src/test/ruby/client" - } - doLast { + delete "src/test/python/client" + + copy { + from "$buildDir/openapi-clients/python/" + into "src/test/python/client" + } + + copy { + from "$buildDir/openapi-clients/ruby/" + into "src/test/ruby/client" + } + project.delete "$buildDir/openapi-clients" } } @@ -70,7 +77,8 @@ dependencies { implementation 'com.google.inject.extensions:guice-servlet:4.2.2' implementation 'com.google.inject.extensions:guice-multibindings:4.2.2' implementation 'com.google.sitebricks:sitebricks:0.8.11' - implementation 'org.openapitools:openapi-generator:4.0.3' + implementation 'org.openapitools:openapi-generator:4.1.0-SNAPSHOT' + implementation 'org.openapitools:openapi-generator-gradle-plugin:4.1.0-SNAPSHOT' testImplementation project(':browserup-proxy-mitm') diff --git a/browserup-proxy-rest-clients/src/test/groovy/com/browserup/bup/python/PythonTestClient.groovy b/browserup-proxy-rest-clients/src/test/groovy/com/browserup/bup/python/PythonTestClient.groovy new file mode 100644 index 000000000..86cf0db31 --- /dev/null +++ b/browserup-proxy-rest-clients/src/test/groovy/com/browserup/bup/python/PythonTestClient.groovy @@ -0,0 +1,106 @@ +/* + * Modifications Copyright (c) 2019 BrowserUp, Inc. + */ + +package com.browserup.bup.python + +import com.browserup.bup.WithRunningProxyRestTest +import org.awaitility.Awaitility +import org.junit.After +import org.junit.Assert +import org.junit.Test +import org.slf4j.Logger +import org.slf4j.LoggerFactory +import org.testcontainers.Testcontainers +import org.testcontainers.containers.GenericContainer +import org.testcontainers.images.builder.ImageFromDockerfile + +import java.nio.file.Path +import java.util.concurrent.TimeUnit + +class PythonTestClient extends WithRunningProxyRestTest { + private static final Logger LOG = LoggerFactory.getLogger(PythonTestClient) + + private GenericContainer container + + @Override + String getUrlPath() { + return 'har/entries' + } + + @After + void shutDown() { + if (container != null) { + container.stop() + } + } + + @Test + void connectToProxySuccessfully() { + def urlToCatch = 'test' + def urlNotToCatch = 'missing' + def responseBody = 'success' + + mockTargetServerResponse(urlToCatch, responseBody) + mockTargetServerResponse(urlNotToCatch, responseBody) + + proxyManager.get()[0].newHar() + + requestToTargetServer(urlToCatch, responseBody) + requestToTargetServer(urlNotToCatch, responseBody) + + Testcontainers.exposeHostPorts(restServer.connectors[0].localPort as Integer) + Testcontainers.exposeHostPorts(proxy.port as Integer) + + def dockerfile = new File('./src/test/python/Dockerfile') + container = new GenericContainer( + new ImageFromDockerfile() + .withDockerfile(Path.of(dockerfile.path))) + .withEnv('PROXY_REST_HOST', 'host.testcontainers.internal') + .withEnv('PROXY_REST_PORT', restServer.connectors[0].localPort as String) + .withEnv('PROXY_PORT', proxy.port as String) + + container.start() + + Awaitility.await().atMost(10, TimeUnit.SECONDS).until({-> !container.isRunning()}) + + LOG.info('Docker log: ' + container.getLogs()) + + Assert.assertEquals("Expected ruby-client container exit code to be 0", 0, container.getCurrentContainerInfo().getState().getExitCode()) + } + + @Test + void failsToConnectToProxy() { + def urlToCatch = 'test' + def urlNotToCatch = 'missing' + def responseBody = 'success' + def invalidProxyPort = 8 + + mockTargetServerResponse(urlToCatch, responseBody) + mockTargetServerResponse(urlNotToCatch, responseBody) + + proxyManager.get()[0].newHar() + + requestToTargetServer(urlToCatch, responseBody) + requestToTargetServer(urlNotToCatch, responseBody) + + Testcontainers.exposeHostPorts(restServer.connectors[0].localPort as Integer) + Testcontainers.exposeHostPorts(proxy.port as Integer) + + def dockerfile = new File('./src/test/python/Dockerfile') + container = new GenericContainer( + new ImageFromDockerfile() + .withDockerfile(Path.of(dockerfile.path))) + .withEnv('PROXY_REST_HOST', 'host.testcontainers.internal') + .withEnv('PROXY_REST_PORT', restServer.connectors[0].localPort as String) + .withEnv('PROXY_PORT', invalidProxyPort as String) + + container.start() + + Awaitility.await().atMost(10, TimeUnit.SECONDS).until({-> !container.isRunning()}) + + LOG.info('Docker log: ' + container.getLogs()) + + Assert.assertEquals("Expected ruby-client container exit code to be 1", 1, container.getCurrentContainerInfo().getState().getExitCode()) + } +} diff --git a/browserup-proxy-rest-clients/src/test/groovy/com/browserup/bup/ruby/RubyClientTest.groovy b/browserup-proxy-rest-clients/src/test/groovy/com/browserup/bup/ruby/RubyClientTest.groovy index 411742505..b0af154a6 100644 --- a/browserup-proxy-rest-clients/src/test/groovy/com/browserup/bup/ruby/RubyClientTest.groovy +++ b/browserup-proxy-rest-clients/src/test/groovy/com/browserup/bup/ruby/RubyClientTest.groovy @@ -6,11 +6,13 @@ package com.browserup.bup.ruby import com.browserup.bup.WithRunningProxyRestTest import org.awaitility.Awaitility +import org.junit.After import org.junit.Assert import org.junit.Test import org.slf4j.Logger import org.slf4j.LoggerFactory import org.testcontainers.Testcontainers +import org.testcontainers.containers.Container import org.testcontainers.containers.GenericContainer import org.testcontainers.images.builder.ImageFromDockerfile @@ -20,11 +22,20 @@ import java.util.concurrent.TimeUnit class RubyClientTest extends WithRunningProxyRestTest { private static final Logger LOG = LoggerFactory.getLogger(RubyClientTest) + private GenericContainer container + @Override String getUrlPath() { return 'har/entries' } + @After + void shutDown() { + if (container != null) { + container.stop() + } + } + @Test void connectToProxy() { def urlToCatch = 'test' @@ -43,7 +54,7 @@ class RubyClientTest extends WithRunningProxyRestTest { Testcontainers.exposeHostPorts(proxy.port as Integer) def dockerfile = new File('./src/test/ruby/Dockerfile') - def container = new GenericContainer( + container = new GenericContainer( new ImageFromDockerfile() .withDockerfile(Path.of(dockerfile.path))) .withEnv('PROXY_REST_HOST', 'host.testcontainers.internal') @@ -58,4 +69,39 @@ class RubyClientTest extends WithRunningProxyRestTest { Assert.assertEquals("Expected ruby-client container exit code to be 0", 0, container.getCurrentContainerInfo().getState().getExitCode()) } + + @Test + void failsToConnectToProxy() { + def urlToCatch = 'test' + def urlNotToCatch = 'missing' + def responseBody = 'success' + def invalidProxyPort = 8 + + mockTargetServerResponse(urlToCatch, responseBody) + mockTargetServerResponse(urlNotToCatch, responseBody) + + proxyManager.get()[0].newHar() + + requestToTargetServer(urlToCatch, responseBody) + requestToTargetServer(urlNotToCatch, responseBody) + + Testcontainers.exposeHostPorts(restServer.connectors[0].localPort as Integer) + Testcontainers.exposeHostPorts(proxy.port as Integer) + + def dockerfile = new File('./src/test/ruby/Dockerfile') + container = new GenericContainer( + new ImageFromDockerfile() + .withDockerfile(Path.of(dockerfile.path))) + .withEnv('PROXY_REST_HOST', 'host.testcontainers.internal') + .withEnv('PROXY_REST_PORT', restServer.connectors[0].localPort as String) + .withEnv('PROXY_PORT', invalidProxyPort as String) + + container.start() + + Awaitility.await().atMost(10, TimeUnit.SECONDS).until({-> !container.isRunning()}) + + LOG.info('Docker log: ' + container.getLogs()) + + Assert.assertEquals("Expected ruby-client container exit code to be 1", 1, container.getCurrentContainerInfo().getState().getExitCode()) + } } diff --git a/browserup-proxy-rest-clients/src/test/python/.gitignore b/browserup-proxy-rest-clients/src/test/python/.gitignore new file mode 100644 index 000000000..7f269dec1 --- /dev/null +++ b/browserup-proxy-rest-clients/src/test/python/.gitignore @@ -0,0 +1 @@ +client/ \ No newline at end of file diff --git a/browserup-proxy-rest-clients/src/test/python/Dockerfile b/browserup-proxy-rest-clients/src/test/python/Dockerfile new file mode 100644 index 000000000..9f7fb443a --- /dev/null +++ b/browserup-proxy-rest-clients/src/test/python/Dockerfile @@ -0,0 +1,17 @@ +FROM python:2.7-alpine + +WORKDIR / + +COPY client/ /python-client/ + +# Build python client, install locally +WORKDIR /python-client/ +RUN python setup.py install --user +RUN pip install -r requirements.txt +RUN pip install -r test-requirements.txt +#RUN python import openapi_client + +COPY . /python/ +WORKDIR /python/ + +CMD ["python", "test/python_test.py"] \ No newline at end of file diff --git a/browserup-proxy-rest-clients/src/test/python/test/python_test.py b/browserup-proxy-rest-clients/src/test/python/test/python_test.py new file mode 100644 index 000000000..8d7b5e9c5 --- /dev/null +++ b/browserup-proxy-rest-clients/src/test/python/test/python_test.py @@ -0,0 +1,22 @@ +from __future__ import print_function +import time +import openapi_client +import os + +from openapi_client.rest import ApiException +from pprint import pprint + +# Create an instance of the API class +api_client = openapi_client.ApiClient() +api_client.configuration.host = 'http://' + os.environ['PROXY_REST_HOST'] + ':' + os.environ['PROXY_REST_PORT'] + +api_instance = openapi_client.DefaultApi(api_client) +port = os.environ['PROXY_PORT'] +url_pattern = '.*' + +try: + api_response = api_instance.entries(port, url_pattern) + pprint(api_response) +except ApiException as e: + print("Exception when calling DefaultApi->entries: %s\n" % e) + raise \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index 25c37126d..cef3ebd69 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,6 +1,27 @@ /* * Modifications Copyright (c) 2019 BrowserUp, Inc. */ +pluginManagement { + resolutionStrategy { + eachPlugin { + if (requested.id.namespace == 'org.openapi') { + useModule('org.openapitools:openapi-generator-gradle-plugin:4.1.0-SNAPSHOT') + } + } + } + repositories { + maven { url "https://oss.sonatype.org/content/repositories/snapshots/" } + maven { url "https://oss.sonatype.org/service/local/staging/deploy/maven2/" } + mavenLocal() + mavenCentral() + gradlePluginPortal().tap { + metadataSources { + mavenPom() + artifact() + } + } + } +} include 'browserup-proxy-core' include 'browserup-proxy-dist' From 69f67aa43cc62b4d5ad3fc229f04d94d80a8aa85 Mon Sep 17 00:00:00 2001 From: "kirill.turutin" Date: Thu, 8 Aug 2019 19:23:17 +0300 Subject: [PATCH 06/12] js client test --- browserup-proxy-rest-clients/build.gradle | 15 +-- .../javascript/JavaScriptClientTest.groovy | 106 ++++++++++++++++++ .../src/test/javascript/.gitignore | 1 + .../src/test/javascript/Dockerfile | 20 ++++ .../test/javascript/test/javascript_test.js | 15 +++ 5 files changed, 148 insertions(+), 9 deletions(-) create mode 100644 browserup-proxy-rest-clients/src/test/groovy/com/browserup/bup/javascript/JavaScriptClientTest.groovy create mode 100644 browserup-proxy-rest-clients/src/test/javascript/.gitignore create mode 100644 browserup-proxy-rest-clients/src/test/javascript/Dockerfile create mode 100644 browserup-proxy-rest-clients/src/test/javascript/test/javascript_test.js diff --git a/browserup-proxy-rest-clients/build.gradle b/browserup-proxy-rest-clients/build.gradle index b59a86183..e5c7c0016 100644 --- a/browserup-proxy-rest-clients/build.gradle +++ b/browserup-proxy-rest-clients/build.gradle @@ -21,7 +21,7 @@ resolve { } def clientLanguages = [ - //'JavaScript', + 'JavaScript', 'Ruby', 'Python' ] @@ -53,14 +53,11 @@ task openApiGenerateClients() { doLast { delete "src/test/python/client" - copy { - from "$buildDir/openapi-clients/python/" - into "src/test/python/client" - } - - copy { - from "$buildDir/openapi-clients/ruby/" - into "src/test/ruby/client" + clientLanguages.each { lang -> + copy { + from "$buildDir/openapi-clients/${lang.toLowerCase()}/" + into "src/test/${lang.toLowerCase()}/client" + } } project.delete "$buildDir/openapi-clients" diff --git a/browserup-proxy-rest-clients/src/test/groovy/com/browserup/bup/javascript/JavaScriptClientTest.groovy b/browserup-proxy-rest-clients/src/test/groovy/com/browserup/bup/javascript/JavaScriptClientTest.groovy new file mode 100644 index 000000000..be300eb69 --- /dev/null +++ b/browserup-proxy-rest-clients/src/test/groovy/com/browserup/bup/javascript/JavaScriptClientTest.groovy @@ -0,0 +1,106 @@ +/* + * Modifications Copyright (c) 2019 BrowserUp, Inc. + */ + +package com.browserup.bup.javascript + +import com.browserup.bup.WithRunningProxyRestTest +import org.awaitility.Awaitility +import org.junit.After +import org.junit.Assert +import org.junit.Test +import org.slf4j.Logger +import org.slf4j.LoggerFactory +import org.testcontainers.Testcontainers +import org.testcontainers.containers.GenericContainer +import org.testcontainers.images.builder.ImageFromDockerfile + +import java.nio.file.Path +import java.util.concurrent.TimeUnit + +class JavaScriptClientTest extends WithRunningProxyRestTest { + private static final Logger LOG = LoggerFactory.getLogger(JavaScriptClientTest) + + private GenericContainer container + + @Override + String getUrlPath() { + return 'har/entries' + } + + @After + void shutDown() { + if (container != null) { + container.stop() + } + } + + @Test + void connectToProxy() { + def urlToCatch = 'test' + def urlNotToCatch = 'missing' + def responseBody = 'success' + + mockTargetServerResponse(urlToCatch, responseBody) + mockTargetServerResponse(urlNotToCatch, responseBody) + + proxyManager.get()[0].newHar() + + requestToTargetServer(urlToCatch, responseBody) + requestToTargetServer(urlNotToCatch, responseBody) + + Testcontainers.exposeHostPorts(restServer.connectors[0].localPort as Integer) + Testcontainers.exposeHostPorts(proxy.port as Integer) + + def dockerfile = new File('./src/test/javascript/Dockerfile') + container = new GenericContainer( + new ImageFromDockerfile() + .withDockerfile(Path.of(dockerfile.path))) + .withEnv('PROXY_REST_HOST', 'host.testcontainers.internal') + .withEnv('PROXY_REST_PORT', restServer.connectors[0].localPort as String) + .withEnv('PROXY_PORT', proxy.port as String) + + container.start() + + Awaitility.await().atMost(10, TimeUnit.SECONDS).until({-> !container.isRunning()}) + + LOG.info('Docker log: ' + container.getLogs()) + + Assert.assertEquals("Expected javascript-client container exit code to be 0", 0, container.getCurrentContainerInfo().getState().getExitCode()) + } + + @Test + void failsToConnectToProxy() { + def urlToCatch = 'test' + def urlNotToCatch = 'missing' + def responseBody = 'success' + def invalidProxyPort = 8 + + mockTargetServerResponse(urlToCatch, responseBody) + mockTargetServerResponse(urlNotToCatch, responseBody) + + proxyManager.get()[0].newHar() + + requestToTargetServer(urlToCatch, responseBody) + requestToTargetServer(urlNotToCatch, responseBody) + + Testcontainers.exposeHostPorts(restServer.connectors[0].localPort as Integer) + Testcontainers.exposeHostPorts(proxy.port as Integer) + + def dockerfile = new File('./src/test/javascript/Dockerfile') + container = new GenericContainer( + new ImageFromDockerfile() + .withDockerfile(Path.of(dockerfile.path))) + .withEnv('PROXY_REST_HOST', 'host.testcontainers.internal') + .withEnv('PROXY_REST_PORT', restServer.connectors[0].localPort as String) + .withEnv('PROXY_PORT', invalidProxyPort as String) + + container.start() + + Awaitility.await().atMost(10, TimeUnit.SECONDS).until({-> !container.isRunning()}) + + LOG.info('Docker log: ' + container.getLogs()) + + Assert.assertEquals("Expected javascript-client container exit code to be 1", 1, container.getCurrentContainerInfo().getState().getExitCode()) + } +} diff --git a/browserup-proxy-rest-clients/src/test/javascript/.gitignore b/browserup-proxy-rest-clients/src/test/javascript/.gitignore new file mode 100644 index 000000000..7f269dec1 --- /dev/null +++ b/browserup-proxy-rest-clients/src/test/javascript/.gitignore @@ -0,0 +1 @@ +client/ \ No newline at end of file diff --git a/browserup-proxy-rest-clients/src/test/javascript/Dockerfile b/browserup-proxy-rest-clients/src/test/javascript/Dockerfile new file mode 100644 index 000000000..0698c79b4 --- /dev/null +++ b/browserup-proxy-rest-clients/src/test/javascript/Dockerfile @@ -0,0 +1,20 @@ +FROM node:8.16.0-alpine + +USER root + +WORKDIR / + +COPY client/ /client/ + +# Build javascript client, install locally +WORKDIR /client/ +RUN rm -rf node_modules/ +RUN npm install +RUN npm link +RUN npm link /client +RUN npm run build + +COPY . /javascript/ +WORKDIR /javascript/ + +CMD ["node", "test/javascript_test.js"] \ No newline at end of file diff --git a/browserup-proxy-rest-clients/src/test/javascript/test/javascript_test.js b/browserup-proxy-rest-clients/src/test/javascript/test/javascript_test.js new file mode 100644 index 000000000..c12a45d74 --- /dev/null +++ b/browserup-proxy-rest-clients/src/test/javascript/test/javascript_test.js @@ -0,0 +1,15 @@ +var BrowserUpProxyApi = require('../client/node_modules/browser_up_proxy_api'); + + +var api = new BrowserUpProxyApi.DefaultApi() +api.basePath = 'http://' + process.env.PROXY_REST_HOST + ':' + process.env.PROXY_REST_PORT +var port = process.env.PROXY_PORT; +var urlPattern = ".*"; +var callback = function(error, data, response) { + if (error) { + console.error(error); + } else { + console.log('API called successfully. Returned data: ' + data); + } +}; +api.entries(port, urlPattern, callback); \ No newline at end of file From 6be0cf40ee93550913cb062d92d9d7869b920626 Mon Sep 17 00:00:00 2001 From: "kirill.turutin" Date: Mon, 12 Aug 2019 13:59:04 +0300 Subject: [PATCH 07/12] Refactoring --- browserup-proxy-rest-clients/build.gradle | 32 ++++++++++--------- .../java/com/CustomRubyClientCodegen.java | 9 ------ .../javascript/JavaScriptClientTest.groovy | 2 ++ .../bup/python/PythonTestClient.groovy | 3 ++ .../test/javascript/test/javascript_test.js | 5 +-- settings.gradle | 21 ------------ 6 files changed, 25 insertions(+), 47 deletions(-) delete mode 100644 browserup-proxy-rest-clients/src/main/java/com/CustomRubyClientCodegen.java diff --git a/browserup-proxy-rest-clients/build.gradle b/browserup-proxy-rest-clients/build.gradle index e5c7c0016..993f06ceb 100644 --- a/browserup-proxy-rest-clients/build.gradle +++ b/browserup-proxy-rest-clients/build.gradle @@ -6,7 +6,7 @@ plugins { id 'java-library' id 'groovy' id "io.swagger.core.v3.swagger-gradle-plugin" version "2.0.8" - id 'org.openapi.generator' version '4.1.0-SNAPSHOT' + id 'org.openapi.generator' version '4.1.0' } resolve { @@ -22,20 +22,20 @@ resolve { def clientLanguages = [ 'JavaScript', - 'Ruby', - 'Python' + 'Ruby' + //https://github.com/OpenAPITools/openapi-generator/issues/3285 + //'Python' ] clientLanguages.each { lang -> - task "openApiGenerate${lang}Client"(type: org.openapitools.generator.gradle.plugin.tasks.GenerateTask) { - dependsOn 'resolve' + task "openApiGenerate${lang}Client"(type: org.openapitools.generator.gradle.plugin.tasks.GenerateTask, dependsOn: resolve) { def language = lang.toLowerCase() generatorName = language inputSpec = "$buildDir/openapi/openapi.yaml".toString() outputDir = "$buildDir/openapi-clients/$language/".toString() -// apiPackage = "api" -// invokerPackage = "invoker" -// modelPackage = "model" + apiPackage = "browserup" + invokerPackage = "browserup.invoker" + modelPackage = "browserup.model" systemProperties = [ modelDocs: 'false' ] @@ -51,12 +51,12 @@ task openApiGenerateClients() { } doLast { - delete "src/test/python/client" - clientLanguages.each { lang -> + def langName = lang.toLowerCase() + delete "src/test/${langName}/client" copy { - from "$buildDir/openapi-clients/${lang.toLowerCase()}/" - into "src/test/${lang.toLowerCase()}/client" + from "$buildDir/openapi-clients/${langName}/" + into "src/test/${langName}/client" } } @@ -74,8 +74,8 @@ dependencies { implementation 'com.google.inject.extensions:guice-servlet:4.2.2' implementation 'com.google.inject.extensions:guice-multibindings:4.2.2' implementation 'com.google.sitebricks:sitebricks:0.8.11' - implementation 'org.openapitools:openapi-generator:4.1.0-SNAPSHOT' - implementation 'org.openapitools:openapi-generator-gradle-plugin:4.1.0-SNAPSHOT' + implementation "org.openapitools:openapi-generator:4.1.0" + implementation "org.openapitools:openapi-generator-gradle-plugin:4.1.0" testImplementation project(':browserup-proxy-mitm') @@ -97,4 +97,6 @@ dependencies { } -build.finalizedBy(openApiGenerateClients) \ No newline at end of file +build.finalizedBy(openApiGenerateClients) + +test.dependsOn(openApiGenerateClients) \ No newline at end of file diff --git a/browserup-proxy-rest-clients/src/main/java/com/CustomRubyClientCodegen.java b/browserup-proxy-rest-clients/src/main/java/com/CustomRubyClientCodegen.java deleted file mode 100644 index df6e98be1..000000000 --- a/browserup-proxy-rest-clients/src/main/java/com/CustomRubyClientCodegen.java +++ /dev/null @@ -1,9 +0,0 @@ -package com; - -import org.openapitools.codegen.languages.RubyClientCodegen; - -public class CustomRubyClientCodegen extends RubyClientCodegen { - public CustomRubyClientCodegen() { - reservedWords.add("send"); - } -} diff --git a/browserup-proxy-rest-clients/src/test/groovy/com/browserup/bup/javascript/JavaScriptClientTest.groovy b/browserup-proxy-rest-clients/src/test/groovy/com/browserup/bup/javascript/JavaScriptClientTest.groovy index be300eb69..687c9a992 100644 --- a/browserup-proxy-rest-clients/src/test/groovy/com/browserup/bup/javascript/JavaScriptClientTest.groovy +++ b/browserup-proxy-rest-clients/src/test/groovy/com/browserup/bup/javascript/JavaScriptClientTest.groovy @@ -52,6 +52,8 @@ class JavaScriptClientTest extends WithRunningProxyRestTest { Testcontainers.exposeHostPorts(restServer.connectors[0].localPort as Integer) Testcontainers.exposeHostPorts(proxy.port as Integer) + new File('./src/test/javascript/client/node_modules').deleteDir() + def dockerfile = new File('./src/test/javascript/Dockerfile') container = new GenericContainer( new ImageFromDockerfile() diff --git a/browserup-proxy-rest-clients/src/test/groovy/com/browserup/bup/python/PythonTestClient.groovy b/browserup-proxy-rest-clients/src/test/groovy/com/browserup/bup/python/PythonTestClient.groovy index 86cf0db31..840411db1 100644 --- a/browserup-proxy-rest-clients/src/test/groovy/com/browserup/bup/python/PythonTestClient.groovy +++ b/browserup-proxy-rest-clients/src/test/groovy/com/browserup/bup/python/PythonTestClient.groovy @@ -8,6 +8,7 @@ import com.browserup.bup.WithRunningProxyRestTest import org.awaitility.Awaitility import org.junit.After import org.junit.Assert +import org.junit.Ignore import org.junit.Test import org.slf4j.Logger import org.slf4j.LoggerFactory @@ -18,6 +19,8 @@ import org.testcontainers.images.builder.ImageFromDockerfile import java.nio.file.Path import java.util.concurrent.TimeUnit +// https://github.com/OpenAPITools/openapi-generator/issues/3285 +@Ignore class PythonTestClient extends WithRunningProxyRestTest { private static final Logger LOG = LoggerFactory.getLogger(PythonTestClient) diff --git a/browserup-proxy-rest-clients/src/test/javascript/test/javascript_test.js b/browserup-proxy-rest-clients/src/test/javascript/test/javascript_test.js index c12a45d74..d5fdd7ea8 100644 --- a/browserup-proxy-rest-clients/src/test/javascript/test/javascript_test.js +++ b/browserup-proxy-rest-clients/src/test/javascript/test/javascript_test.js @@ -1,13 +1,14 @@ -var BrowserUpProxyApi = require('../client/node_modules/browser_up_proxy_api'); +var BrowserUpProxyApi = require('/client/node_modules/browser_up_proxy_api'); var api = new BrowserUpProxyApi.DefaultApi() -api.basePath = 'http://' + process.env.PROXY_REST_HOST + ':' + process.env.PROXY_REST_PORT +api.apiClient.basePath = 'http://' + process.env.PROXY_REST_HOST + ':' + process.env.PROXY_REST_PORT var port = process.env.PROXY_PORT; var urlPattern = ".*"; var callback = function(error, data, response) { if (error) { console.error(error); + throw new Error(error); } else { console.log('API called successfully. Returned data: ' + data); } diff --git a/settings.gradle b/settings.gradle index cef3ebd69..25c37126d 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,27 +1,6 @@ /* * Modifications Copyright (c) 2019 BrowserUp, Inc. */ -pluginManagement { - resolutionStrategy { - eachPlugin { - if (requested.id.namespace == 'org.openapi') { - useModule('org.openapitools:openapi-generator-gradle-plugin:4.1.0-SNAPSHOT') - } - } - } - repositories { - maven { url "https://oss.sonatype.org/content/repositories/snapshots/" } - maven { url "https://oss.sonatype.org/service/local/staging/deploy/maven2/" } - mavenLocal() - mavenCentral() - gradlePluginPortal().tap { - metadataSources { - mavenPom() - artifact() - } - } - } -} include 'browserup-proxy-core' include 'browserup-proxy-dist' From 728c6f203ee40a5058e4093af8376973c5141ebb Mon Sep 17 00:00:00 2001 From: "kirill.turutin" Date: Tue, 13 Aug 2019 10:57:01 +0300 Subject: [PATCH 08/12] Refactoring --- browserup-proxy-rest-clients/build.gradle | 21 +++++++------------ .../src/test/javascript/Dockerfile | 2 +- .../src/test/ruby/Dockerfile | 2 +- build.gradle | 1 + 4 files changed, 11 insertions(+), 15 deletions(-) diff --git a/browserup-proxy-rest-clients/build.gradle b/browserup-proxy-rest-clients/build.gradle index 993f06ceb..7f0df9334 100644 --- a/browserup-proxy-rest-clients/build.gradle +++ b/browserup-proxy-rest-clients/build.gradle @@ -23,7 +23,7 @@ resolve { def clientLanguages = [ 'JavaScript', 'Ruby' - //https://github.com/OpenAPITools/openapi-generator/issues/3285 + //https://github.com/OpenAPITools/openapi-generator/issues/3285 //'Python' ] @@ -69,15 +69,14 @@ archivesBaseName = 'browserup-proxy-rest-clients' dependencies { implementation project(':browserup-proxy-core') implementation project(':browserup-proxy-rest') + + testImplementation project(':browserup-proxy-mitm') - implementation 'com.google.inject:guice:4.2.2' - implementation 'com.google.inject.extensions:guice-servlet:4.2.2' - implementation 'com.google.inject.extensions:guice-multibindings:4.2.2' - implementation 'com.google.sitebricks:sitebricks:0.8.11' - implementation "org.openapitools:openapi-generator:4.1.0" - implementation "org.openapitools:openapi-generator-gradle-plugin:4.1.0" + testImplementation "com.google.inject:guice:$guiceVersion" + testImplementation "com.google.inject.extensions:guice-servlet:$guiceVersion" + testImplementation "com.google.inject.extensions:guice-multibindings:$guiceVersion" - testImplementation project(':browserup-proxy-mitm') + testImplementation 'com.google.sitebricks:sitebricks:0.8.11' testImplementation 'junit:junit:4.12' testImplementation "org.apache.logging.log4j:log4j-api:${log4jVersion}" @@ -93,10 +92,6 @@ dependencies { testImplementation 'xyz.rogfam:littleproxy:2.0.0-beta-3' testImplementation 'com.github.tomakehurst:wiremock-jre8:2.24.0' testImplementation 'org.testcontainers:testcontainers:1.12.0' - - } -build.finalizedBy(openApiGenerateClients) - -test.dependsOn(openApiGenerateClients) \ No newline at end of file +build.finalizedBy(openApiGenerateClients) \ No newline at end of file diff --git a/browserup-proxy-rest-clients/src/test/javascript/Dockerfile b/browserup-proxy-rest-clients/src/test/javascript/Dockerfile index 0698c79b4..a60a240eb 100644 --- a/browserup-proxy-rest-clients/src/test/javascript/Dockerfile +++ b/browserup-proxy-rest-clients/src/test/javascript/Dockerfile @@ -4,7 +4,7 @@ USER root WORKDIR / -COPY client/ /client/ +COPY ./client/ /client/ # Build javascript client, install locally WORKDIR /client/ diff --git a/browserup-proxy-rest-clients/src/test/ruby/Dockerfile b/browserup-proxy-rest-clients/src/test/ruby/Dockerfile index 66d1ffce6..20b1e543f 100644 --- a/browserup-proxy-rest-clients/src/test/ruby/Dockerfile +++ b/browserup-proxy-rest-clients/src/test/ruby/Dockerfile @@ -4,7 +4,7 @@ RUN bundle config --global frozen 1 WORKDIR / -COPY client/ /ruby-client/ +COPY ./client/ /ruby-client/ # Build ruby client gem, install locally WORKDIR /ruby-client/ diff --git a/build.gradle b/build.gradle index 6beeb6bf7..7ebeb31f5 100644 --- a/build.gradle +++ b/build.gradle @@ -23,6 +23,7 @@ configurations.all { ext { jerseyVersion = '2.29' + guiceVersion = '4.2.2' } subprojects { From 1322eef3b4b1b39d2690045dfdc24f28e9e8f88d Mon Sep 17 00:00:00 2001 From: "kirill.turutin" Date: Tue, 13 Aug 2019 14:46:26 +0300 Subject: [PATCH 09/12] build fix --- browserup-proxy-rest-clients/build.gradle | 16 +++++++++++----- .../src/test/resources/log4j2-test.json | 18 ++++++++++++++++++ 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/browserup-proxy-rest-clients/build.gradle b/browserup-proxy-rest-clients/build.gradle index 7f0df9334..13423042b 100644 --- a/browserup-proxy-rest-clients/build.gradle +++ b/browserup-proxy-rest-clients/build.gradle @@ -17,7 +17,7 @@ resolve { classpath = sourceSets.main.runtimeClasspath readerClass = "com.browserup.bup.rest.openapi.CustomOpenApiReader" resourcePackages = ['com.browserup.bup.rest.resource'] - outputPath = 'build/openapi' + outputPath = "$buildDir/openapi" } def clientLanguages = [ @@ -28,7 +28,7 @@ def clientLanguages = [ ] clientLanguages.each { lang -> - task "openApiGenerate${lang}Client"(type: org.openapitools.generator.gradle.plugin.tasks.GenerateTask, dependsOn: resolve) { + task "openApiGenerate${lang}Client"(type: org.openapitools.generator.gradle.plugin.tasks.GenerateTask) { def language = lang.toLowerCase() generatorName = language inputSpec = "$buildDir/openapi/openapi.yaml".toString() @@ -45,7 +45,11 @@ clientLanguages.each { lang -> } } -task openApiGenerateClients() { +test { + testLogging.showStandardStreams = true +} + +task openApiGenerateClients(dependsOn: resolve) { clientLanguages.each { lang -> dependsOn "openApiGenerate${lang}Client" } @@ -69,7 +73,7 @@ archivesBaseName = 'browserup-proxy-rest-clients' dependencies { implementation project(':browserup-proxy-core') implementation project(':browserup-proxy-rest') - + testImplementation project(':browserup-proxy-mitm') testImplementation "com.google.inject:guice:$guiceVersion" @@ -94,4 +98,6 @@ dependencies { testImplementation 'org.testcontainers:testcontainers:1.12.0' } -build.finalizedBy(openApiGenerateClients) \ No newline at end of file +openApiGenerateClients.mustRunAfter(resolve) + +test.dependsOn(openApiGenerateClients) diff --git a/browserup-proxy-rest-clients/src/test/resources/log4j2-test.json b/browserup-proxy-rest-clients/src/test/resources/log4j2-test.json index f3e5e72ec..616ff8763 100644 --- a/browserup-proxy-rest-clients/src/test/resources/log4j2-test.json +++ b/browserup-proxy-rest-clients/src/test/resources/log4j2-test.json @@ -12,6 +12,24 @@ }, "loggers": { + "logger": [ + { + "name": "org.testcontainers", + "level": "warn", + "additivity": false, + "AppenderRef": { + "ref": "console" + } + }, + { + "name": "com.github.dockerjava", + "level": "warn", + "additivity": false, + "AppenderRef": { + "ref": "console" + } + } + ], "root": { "level": "info", "appender-ref": { From 3bb813b7eda4bdda6f141a1c080ef3d88169de58 Mon Sep 17 00:00:00 2001 From: "kirill.turutin" Date: Tue, 4 Feb 2020 12:17:39 +0300 Subject: [PATCH 10/12] update dependencies --- browserup-proxy-rest-clients/build.gradle | 4 ++-- .../browserup/bup/javascript/JavaScriptClientTest.groovy | 5 +++-- .../groovy/com/browserup/bup/python/PythonTestClient.groovy | 6 ++++-- .../groovy/com/browserup/bup/ruby/RubyClientTest.groovy | 5 +++-- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/browserup-proxy-rest-clients/build.gradle b/browserup-proxy-rest-clients/build.gradle index 13423042b..be34a8260 100644 --- a/browserup-proxy-rest-clients/build.gradle +++ b/browserup-proxy-rest-clients/build.gradle @@ -5,8 +5,8 @@ plugins { id 'java-library' id 'groovy' - id "io.swagger.core.v3.swagger-gradle-plugin" version "2.0.8" - id 'org.openapi.generator' version '4.1.0' + id "io.swagger.core.v3.swagger-gradle-plugin" version "2.1.1" + id 'org.openapi.generator' version '4.2.3' } resolve { diff --git a/browserup-proxy-rest-clients/src/test/groovy/com/browserup/bup/javascript/JavaScriptClientTest.groovy b/browserup-proxy-rest-clients/src/test/groovy/com/browserup/bup/javascript/JavaScriptClientTest.groovy index 687c9a992..7f11824ce 100644 --- a/browserup-proxy-rest-clients/src/test/groovy/com/browserup/bup/javascript/JavaScriptClientTest.groovy +++ b/browserup-proxy-rest-clients/src/test/groovy/com/browserup/bup/javascript/JavaScriptClientTest.groovy @@ -16,6 +16,7 @@ import org.testcontainers.containers.GenericContainer import org.testcontainers.images.builder.ImageFromDockerfile import java.nio.file.Path +import java.nio.file.Paths import java.util.concurrent.TimeUnit class JavaScriptClientTest extends WithRunningProxyRestTest { @@ -57,7 +58,7 @@ class JavaScriptClientTest extends WithRunningProxyRestTest { def dockerfile = new File('./src/test/javascript/Dockerfile') container = new GenericContainer( new ImageFromDockerfile() - .withDockerfile(Path.of(dockerfile.path))) + .withDockerfile(Paths.get(dockerfile.path))) .withEnv('PROXY_REST_HOST', 'host.testcontainers.internal') .withEnv('PROXY_REST_PORT', restServer.connectors[0].localPort as String) .withEnv('PROXY_PORT', proxy.port as String) @@ -92,7 +93,7 @@ class JavaScriptClientTest extends WithRunningProxyRestTest { def dockerfile = new File('./src/test/javascript/Dockerfile') container = new GenericContainer( new ImageFromDockerfile() - .withDockerfile(Path.of(dockerfile.path))) + .withDockerfile(Paths.get(dockerfile.path))) .withEnv('PROXY_REST_HOST', 'host.testcontainers.internal') .withEnv('PROXY_REST_PORT', restServer.connectors[0].localPort as String) .withEnv('PROXY_PORT', invalidProxyPort as String) diff --git a/browserup-proxy-rest-clients/src/test/groovy/com/browserup/bup/python/PythonTestClient.groovy b/browserup-proxy-rest-clients/src/test/groovy/com/browserup/bup/python/PythonTestClient.groovy index 840411db1..69e9882a6 100644 --- a/browserup-proxy-rest-clients/src/test/groovy/com/browserup/bup/python/PythonTestClient.groovy +++ b/browserup-proxy-rest-clients/src/test/groovy/com/browserup/bup/python/PythonTestClient.groovy @@ -17,6 +17,7 @@ import org.testcontainers.containers.GenericContainer import org.testcontainers.images.builder.ImageFromDockerfile import java.nio.file.Path +import java.nio.file.Paths import java.util.concurrent.TimeUnit // https://github.com/OpenAPITools/openapi-generator/issues/3285 @@ -58,7 +59,7 @@ class PythonTestClient extends WithRunningProxyRestTest { def dockerfile = new File('./src/test/python/Dockerfile') container = new GenericContainer( new ImageFromDockerfile() - .withDockerfile(Path.of(dockerfile.path))) + .withDockerfile(Paths.get(dockerfile.path))) .withEnv('PROXY_REST_HOST', 'host.testcontainers.internal') .withEnv('PROXY_REST_PORT', restServer.connectors[0].localPort as String) .withEnv('PROXY_PORT', proxy.port as String) @@ -93,7 +94,7 @@ class PythonTestClient extends WithRunningProxyRestTest { def dockerfile = new File('./src/test/python/Dockerfile') container = new GenericContainer( new ImageFromDockerfile() - .withDockerfile(Path.of(dockerfile.path))) + .withDockerfile(Paths.get(dockerfile.path))) .withEnv('PROXY_REST_HOST', 'host.testcontainers.internal') .withEnv('PROXY_REST_PORT', restServer.connectors[0].localPort as String) .withEnv('PROXY_PORT', invalidProxyPort as String) @@ -107,3 +108,4 @@ class PythonTestClient extends WithRunningProxyRestTest { Assert.assertEquals("Expected ruby-client container exit code to be 1", 1, container.getCurrentContainerInfo().getState().getExitCode()) } } + diff --git a/browserup-proxy-rest-clients/src/test/groovy/com/browserup/bup/ruby/RubyClientTest.groovy b/browserup-proxy-rest-clients/src/test/groovy/com/browserup/bup/ruby/RubyClientTest.groovy index b0af154a6..90ae48276 100644 --- a/browserup-proxy-rest-clients/src/test/groovy/com/browserup/bup/ruby/RubyClientTest.groovy +++ b/browserup-proxy-rest-clients/src/test/groovy/com/browserup/bup/ruby/RubyClientTest.groovy @@ -17,6 +17,7 @@ import org.testcontainers.containers.GenericContainer import org.testcontainers.images.builder.ImageFromDockerfile import java.nio.file.Path +import java.nio.file.Paths import java.util.concurrent.TimeUnit class RubyClientTest extends WithRunningProxyRestTest { @@ -56,7 +57,7 @@ class RubyClientTest extends WithRunningProxyRestTest { def dockerfile = new File('./src/test/ruby/Dockerfile') container = new GenericContainer( new ImageFromDockerfile() - .withDockerfile(Path.of(dockerfile.path))) + .withDockerfile(Paths.get(dockerfile.path))) .withEnv('PROXY_REST_HOST', 'host.testcontainers.internal') .withEnv('PROXY_REST_PORT', restServer.connectors[0].localPort as String) .withEnv('PROXY_PORT', proxy.port as String) @@ -91,7 +92,7 @@ class RubyClientTest extends WithRunningProxyRestTest { def dockerfile = new File('./src/test/ruby/Dockerfile') container = new GenericContainer( new ImageFromDockerfile() - .withDockerfile(Path.of(dockerfile.path))) + .withDockerfile(Paths.get(dockerfile.path))) .withEnv('PROXY_REST_HOST', 'host.testcontainers.internal') .withEnv('PROXY_REST_PORT', restServer.connectors[0].localPort as String) .withEnv('PROXY_PORT', invalidProxyPort as String) From 652e024ad3408988f8d1e73815bc64c4590fea07 Mon Sep 17 00:00:00 2001 From: "kirill.turutin" Date: Fri, 7 Feb 2020 14:50:46 +0300 Subject: [PATCH 11/12] python client fix --- browserup-proxy-rest-clients/build.gradle | 68 +++++++++++++++---- .../bup/python/PythonTestClient.groovy | 6 +- .../src/test/python/Dockerfile | 1 - 3 files changed, 56 insertions(+), 19 deletions(-) diff --git a/browserup-proxy-rest-clients/build.gradle b/browserup-proxy-rest-clients/build.gradle index be34a8260..6a11fc84a 100644 --- a/browserup-proxy-rest-clients/build.gradle +++ b/browserup-proxy-rest-clients/build.gradle @@ -20,22 +20,61 @@ resolve { outputPath = "$buildDir/openapi" } -def clientLanguages = [ - 'JavaScript', - 'Ruby' - //https://github.com/OpenAPITools/openapi-generator/issues/3285 - //'Python' -] - -clientLanguages.each { lang -> +class Constants { + static String apiPackage = 'browserup' + static String modelPackage = 'browserup.model' +} + +/* + https://github.com/OpenAPITools/openapi-generator/issues/3285 + */ +class PythonClientPostProcessor { + String projectDir + + void process() { + def clientDir = new File("$projectDir/build/openapi-clients/python") + clientDir.eachFileRecurse { + if (it.name.endsWith(".py")) { + processInitFile(it) + } + } + new File("${clientDir}/openapi_client/${Constants.apiPackage}/model/__init__.py") << + new File("${clientDir}/openapi_client/${Constants.modelPackage}/__init__.py").text + } + + private static void processInitFile(File initFile) { + initFile.text = initFile.text.replaceAll( + ~/(from ${Constants.apiPackage}.default_api import)/, + "from openapi_client.${Constants.apiPackage}.default_api import" + ) + } +} + +class ClientInfo { + String language + Closure postProcessor +} + +def clients = [ + new ClientInfo(language: 'JavaScript'), + new ClientInfo(language: 'Ruby'), + new ClientInfo( + language: 'Python', + postProcessor: new PythonClientPostProcessor(projectDir: projectDir).&process) +] as ClientInfo[] + +clients.each { client -> + def lang = client.language + def postProcessor = client.postProcessor + task "openApiGenerate${lang}Client"(type: org.openapitools.generator.gradle.plugin.tasks.GenerateTask) { def language = lang.toLowerCase() generatorName = language inputSpec = "$buildDir/openapi/openapi.yaml".toString() outputDir = "$buildDir/openapi-clients/$language/".toString() - apiPackage = "browserup" + apiPackage = Constants.apiPackage + modelPackage = Constants.modelPackage invokerPackage = "browserup.invoker" - modelPackage = "browserup.model" systemProperties = [ modelDocs: 'false' ] @@ -43,6 +82,7 @@ clientLanguages.each { lang -> logToStderr = true generateAliasAsModel = false } + if (postProcessor) tasks.getByName("openApiGenerate${lang}Client").doLast(postProcessor) } test { @@ -50,13 +90,13 @@ test { } task openApiGenerateClients(dependsOn: resolve) { - clientLanguages.each { lang -> - dependsOn "openApiGenerate${lang}Client" + clients.each { c -> + dependsOn "openApiGenerate${c.language}Client" } doLast { - clientLanguages.each { lang -> - def langName = lang.toLowerCase() + clients.each { client -> + def langName = client.language.toLowerCase() delete "src/test/${langName}/client" copy { from "$buildDir/openapi-clients/${langName}/" diff --git a/browserup-proxy-rest-clients/src/test/groovy/com/browserup/bup/python/PythonTestClient.groovy b/browserup-proxy-rest-clients/src/test/groovy/com/browserup/bup/python/PythonTestClient.groovy index 69e9882a6..d1c8b5da8 100644 --- a/browserup-proxy-rest-clients/src/test/groovy/com/browserup/bup/python/PythonTestClient.groovy +++ b/browserup-proxy-rest-clients/src/test/groovy/com/browserup/bup/python/PythonTestClient.groovy @@ -20,8 +20,6 @@ import java.nio.file.Path import java.nio.file.Paths import java.util.concurrent.TimeUnit -// https://github.com/OpenAPITools/openapi-generator/issues/3285 -@Ignore class PythonTestClient extends WithRunningProxyRestTest { private static final Logger LOG = LoggerFactory.getLogger(PythonTestClient) @@ -70,7 +68,7 @@ class PythonTestClient extends WithRunningProxyRestTest { LOG.info('Docker log: ' + container.getLogs()) - Assert.assertEquals("Expected ruby-client container exit code to be 0", 0, container.getCurrentContainerInfo().getState().getExitCode()) + Assert.assertEquals("Expected python-client container exit code to be 0", 0, container.getCurrentContainerInfo().getState().getExitCode()) } @Test @@ -105,7 +103,7 @@ class PythonTestClient extends WithRunningProxyRestTest { LOG.info('Docker log: ' + container.getLogs()) - Assert.assertEquals("Expected ruby-client container exit code to be 1", 1, container.getCurrentContainerInfo().getState().getExitCode()) + Assert.assertEquals("Expected python-client container exit code to be 1", 1, container.getCurrentContainerInfo().getState().getExitCode()) } } diff --git a/browserup-proxy-rest-clients/src/test/python/Dockerfile b/browserup-proxy-rest-clients/src/test/python/Dockerfile index 9f7fb443a..cdf081547 100644 --- a/browserup-proxy-rest-clients/src/test/python/Dockerfile +++ b/browserup-proxy-rest-clients/src/test/python/Dockerfile @@ -9,7 +9,6 @@ WORKDIR /python-client/ RUN python setup.py install --user RUN pip install -r requirements.txt RUN pip install -r test-requirements.txt -#RUN python import openapi_client COPY . /python/ WORKDIR /python/ From 156427871acc326cb70af237ad4da00db8ab4ddb Mon Sep 17 00:00:00 2001 From: "kirill.turutin" Date: Tue, 15 Dec 2020 13:25:45 +0300 Subject: [PATCH 12/12] Tests fixes --- browserup-proxy-rest-clients/build.gradle | 15 +++++++-- .../bup/WithRunningProxyRestTest.groovy | 33 +++++++++++-------- .../entries/EntriesProxyResource.java | 3 +- 3 files changed, 32 insertions(+), 19 deletions(-) diff --git a/browserup-proxy-rest-clients/build.gradle b/browserup-proxy-rest-clients/build.gradle index 6a11fc84a..eaf95fbce 100644 --- a/browserup-proxy-rest-clients/build.gradle +++ b/browserup-proxy-rest-clients/build.gradle @@ -5,8 +5,12 @@ plugins { id 'java-library' id 'groovy' - id "io.swagger.core.v3.swagger-gradle-plugin" version "2.1.1" - id 'org.openapi.generator' version '4.2.3' + id "io.swagger.core.v3.swagger-gradle-plugin" version "2.1.6" + id 'org.openapi.generator' version '4.3.1' +} + +ext { + jerseyVersion = '2.32' } resolve { @@ -66,7 +70,7 @@ def clients = [ clients.each { client -> def lang = client.language def postProcessor = client.postProcessor - + task "openApiGenerate${lang}Client"(type: org.openapitools.generator.gradle.plugin.tasks.GenerateTask) { def language = lang.toLowerCase() generatorName = language @@ -114,6 +118,11 @@ dependencies { implementation project(':browserup-proxy-core') implementation project(':browserup-proxy-rest') + testImplementation "org.glassfish.jersey.containers:jersey-container-servlet-core:${jerseyVersion}" + testImplementation "org.glassfish.jersey.media:jersey-media-json-jackson:${jerseyVersion}" + testImplementation "org.glassfish.jersey.inject:jersey-hk2:${jerseyVersion}" + testImplementation "org.glassfish.jersey.ext:jersey-bean-validation:${jerseyVersion}" + testImplementation project(':browserup-proxy-mitm') testImplementation "com.google.inject:guice:$guiceVersion" diff --git a/browserup-proxy-rest-clients/src/test/groovy/com/browserup/bup/WithRunningProxyRestTest.groovy b/browserup-proxy-rest-clients/src/test/groovy/com/browserup/bup/WithRunningProxyRestTest.groovy index 38d8dbffd..997fb1a3f 100644 --- a/browserup-proxy-rest-clients/src/test/groovy/com/browserup/bup/WithRunningProxyRestTest.groovy +++ b/browserup-proxy-rest-clients/src/test/groovy/com/browserup/bup/WithRunningProxyRestTest.groovy @@ -4,14 +4,16 @@ package com.browserup.bup -import com.browserup.bup.BrowserUpProxyServer -import com.browserup.bup.proxy.ProxyManager +/* + * Modifications Copyright (c) 2019 BrowserUp, Inc. + */ + +import com.browserup.bup.MitmProxyServer +import com.browserup.bup.proxy.MitmProxyManager import com.browserup.bup.proxy.bricks.ProxyResource import com.browserup.bup.proxy.guice.ConfigModule import com.browserup.bup.proxy.guice.JettyModule import com.browserup.bup.util.BrowserUpProxyUtil -import com.github.tomakehurst.wiremock.client.WireMock -import com.github.tomakehurst.wiremock.core.WireMockConfiguration import com.github.tomakehurst.wiremock.junit.WireMockRule import com.google.inject.Guice import com.google.inject.Injector @@ -24,7 +26,6 @@ import org.awaitility.Awaitility import org.eclipse.jetty.server.Server import org.eclipse.jetty.servlet.ServletContextHandler import org.junit.After -import org.junit.Assert import org.junit.Before import org.junit.Rule import org.slf4j.Logger @@ -33,11 +34,15 @@ import org.slf4j.LoggerFactory import javax.servlet.ServletContextEvent import java.util.concurrent.TimeUnit +import static com.github.tomakehurst.wiremock.client.WireMock.* +import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options +import static org.junit.Assert.assertEquals + abstract class WithRunningProxyRestTest { - private static final Logger LOG = LoggerFactory.getLogger(WithRunningProxyRestTest) + private static final Logger LOG = LoggerFactory.getLogger(MitmProxyManager) - protected ProxyManager proxyManager - protected BrowserUpProxyServer proxy + protected MitmProxyManager proxyManager + protected MitmProxyServer proxy protected Server restServer protected String[] getArgs() { @@ -54,7 +59,7 @@ abstract class WithRunningProxyRestTest { protected int mockServerHttpsPort @Rule - public WireMockRule wireMockRule = new WireMockRule(WireMockConfiguration.options().port(0).httpsPort(0)) + public WireMockRule wireMockRule = new WireMockRule(options().port(0).httpsPort(0)) @Before void setUp() throws Exception { @@ -65,7 +70,7 @@ abstract class WithRunningProxyRestTest { } }) - proxyManager = injector.getInstance(ProxyManager) + proxyManager = injector.getInstance(MitmProxyManager) LOG.debug("Starting BrowserUp Proxy version " + BrowserUpProxyUtil.versionString) @@ -130,10 +135,10 @@ abstract class WithRunningProxyRestTest { targetServerClient.request(Method.GET, ContentType.TEXT_PLAIN) { req -> uri.path = "/${url}" response.success = { _, reader -> - Assert.assertEquals(expectedResponse, reader.text) + assertEquals(expectedResponse, reader.text) } response.failure = { _, reader -> - Assert.assertEquals(expectedResponse, reader.text) + assertEquals(expectedResponse, reader.text) } } } @@ -178,10 +183,10 @@ abstract class WithRunningProxyRestTest { } protected void mockTargetServerResponse(String url, String responseBody, int delayMilliseconds=0) { - def response = WireMock.aResponse().withStatus(200) + def response = aResponse().withStatus(200) .withBody(responseBody) .withHeader('Content-Type', 'text/plain') .withFixedDelay(delayMilliseconds) - WireMock.stubFor(WireMock.get(WireMock.urlEqualTo("/${url}")).willReturn(response)) + stubFor(get(urlEqualTo("/${url}")).willReturn(response)) } } diff --git a/browserup-proxy-rest/src/main/java/com/browserup/bup/rest/resource/entries/EntriesProxyResource.java b/browserup-proxy-rest/src/main/java/com/browserup/bup/rest/resource/entries/EntriesProxyResource.java index c8a6a436d..0e6da6896 100644 --- a/browserup-proxy-rest/src/main/java/com/browserup/bup/rest/resource/entries/EntriesProxyResource.java +++ b/browserup-proxy-rest/src/main/java/com/browserup/bup/rest/resource/entries/EntriesProxyResource.java @@ -1,10 +1,9 @@ package com.browserup.bup.rest.resource.entries; -import com.browserup.bup.BrowserUpProxyServer; import com.browserup.bup.MitmProxyServer; import com.browserup.bup.assertion.model.AssertionResult; import com.browserup.bup.proxy.MitmProxyManager; -import com.browserup.bup.rest.swagger.DocConstants; +import com.browserup.bup.rest.openapi.DocConstants; import com.browserup.bup.rest.validation.HttpStatusCodeConstraint; import com.browserup.bup.rest.validation.LongPositiveConstraint; import com.browserup.bup.rest.validation.NotBlankConstraint;