From 2dda908c7ef307c40737ece4ebeffb09ad4a31b6 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Tue, 26 Mar 2019 12:00:27 +0000 Subject: [PATCH] Polish "Use HTTPS for externals links where possible" See gh-611 --- .../PrettyPrintingContentModifier.java | 2 +- .../LinkExtractorsPayloadTests.java | 3 ++- ...riModifyingOperationPreprocessorTests.java | 8 +++---- ...riModifyingOperationPreprocessorTests.java | 22 +++++++++---------- 4 files changed, 18 insertions(+), 17 deletions(-) diff --git a/spring-restdocs-core/src/main/java/org/springframework/restdocs/operation/preprocess/PrettyPrintingContentModifier.java b/spring-restdocs-core/src/main/java/org/springframework/restdocs/operation/preprocess/PrettyPrintingContentModifier.java index 879aa40d..c38c5ff5 100644 --- a/spring-restdocs-core/src/main/java/org/springframework/restdocs/operation/preprocess/PrettyPrintingContentModifier.java +++ b/spring-restdocs-core/src/main/java/org/springframework/restdocs/operation/preprocess/PrettyPrintingContentModifier.java @@ -82,7 +82,7 @@ public class PrettyPrintingContentModifier implements ContentModifier { public byte[] prettyPrint(byte[] original) throws Exception { Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); - transformer.setOutputProperty("{https://xml.apache.org/xslt}indent-amount", + transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4"); transformer.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC, "yes"); ByteArrayOutputStream transformed = new ByteArrayOutputStream(); diff --git a/spring-restdocs-core/src/test/java/org/springframework/restdocs/hypermedia/LinkExtractorsPayloadTests.java b/spring-restdocs-core/src/test/java/org/springframework/restdocs/hypermedia/LinkExtractorsPayloadTests.java index d868297a..ea0d4a02 100644 --- a/spring-restdocs-core/src/test/java/org/springframework/restdocs/hypermedia/LinkExtractorsPayloadTests.java +++ b/spring-restdocs-core/src/test/java/org/springframework/restdocs/hypermedia/LinkExtractorsPayloadTests.java @@ -68,7 +68,8 @@ public class LinkExtractorsPayloadTests { public void singleLink() throws IOException { Map> links = this.linkExtractor .extractLinks(createResponse("single-link")); - assertLinks(Arrays.asList(new Link("alpha", "https://alpha.example.com", "Alpha")), + assertLinks( + Arrays.asList(new Link("alpha", "https://alpha.example.com", "Alpha")), links); } diff --git a/spring-restdocs-restassured/src/test/java/org/springframework/restdocs/restassured/operation/preprocess/UriModifyingOperationPreprocessorTests.java b/spring-restdocs-restassured/src/test/java/org/springframework/restdocs/restassured/operation/preprocess/UriModifyingOperationPreprocessorTests.java index 9a7ab00e..ce2b99e1 100644 --- a/spring-restdocs-restassured/src/test/java/org/springframework/restdocs/restassured/operation/preprocess/UriModifyingOperationPreprocessorTests.java +++ b/spring-restdocs-restassured/src/test/java/org/springframework/restdocs/restassured/operation/preprocess/UriModifyingOperationPreprocessorTests.java @@ -94,8 +94,8 @@ public class UriModifyingOperationPreprocessorTests { @Test public void requestUriPathIsPreserved() { this.preprocessor.removePort(); - OperationRequest processed = this.preprocessor - .preprocess(createRequestWithUri("https://api.example.com:12345/foo/bar")); + OperationRequest processed = this.preprocessor.preprocess( + createRequestWithUri("https://api.example.com:12345/foo/bar")); assertThat(processed.getUri()) .isEqualTo(URI.create("https://api.example.com/foo/bar")); } @@ -103,8 +103,8 @@ public class UriModifyingOperationPreprocessorTests { @Test public void requestUriQueryIsPreserved() { this.preprocessor.removePort(); - OperationRequest processed = this.preprocessor - .preprocess(createRequestWithUri("https://api.example.com:12345?foo=bar")); + OperationRequest processed = this.preprocessor.preprocess( + createRequestWithUri("https://api.example.com:12345?foo=bar")); assertThat(processed.getUri()) .isEqualTo(URI.create("https://api.example.com?foo=bar")); } diff --git a/spring-restdocs-restassured/src/test/java/org/springframework/restdocs/restassured3/operation/preprocess/UriModifyingOperationPreprocessorTests.java b/spring-restdocs-restassured/src/test/java/org/springframework/restdocs/restassured3/operation/preprocess/UriModifyingOperationPreprocessorTests.java index 349d5bc2..efcefd5a 100644 --- a/spring-restdocs-restassured/src/test/java/org/springframework/restdocs/restassured3/operation/preprocess/UriModifyingOperationPreprocessorTests.java +++ b/spring-restdocs-restassured/src/test/java/org/springframework/restdocs/restassured3/operation/preprocess/UriModifyingOperationPreprocessorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2016 the original author or authors. + * Copyright 2014-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -93,8 +93,8 @@ public class UriModifyingOperationPreprocessorTests { @Test public void requestUriPathIsPreserved() { this.preprocessor.removePort(); - OperationRequest processed = this.preprocessor - .preprocess(createRequestWithUri("https://api.example.com:12345/foo/bar")); + OperationRequest processed = this.preprocessor.preprocess( + createRequestWithUri("https://api.example.com:12345/foo/bar")); assertThat(processed.getUri()) .isEqualTo(URI.create("https://api.example.com/foo/bar")); } @@ -102,8 +102,8 @@ public class UriModifyingOperationPreprocessorTests { @Test public void requestUriQueryIsPreserved() { this.preprocessor.removePort(); - OperationRequest processed = this.preprocessor - .preprocess(createRequestWithUri("https://api.example.com:12345?foo=bar")); + OperationRequest processed = this.preprocessor.preprocess( + createRequestWithUri("https://api.example.com:12345?foo=bar")); assertThat(processed.getUri()) .isEqualTo(URI.create("https://api.example.com?foo=bar")); } @@ -132,7 +132,7 @@ public class UriModifyingOperationPreprocessorTests { this.preprocessor.host("api.example.com"); OperationRequest processed = this.preprocessor .preprocess(createRequestWithContent( - "The uri 'http://localhost:12345' should be used")); + "The uri 'https://localhost:12345' should be used")); assertThat(new String(processed.getContent())) .isEqualTo("The uri 'https://api.example.com:12345' should be used"); } @@ -212,7 +212,7 @@ public class UriModifyingOperationPreprocessorTests { this.preprocessor.host("api.example.com"); OperationResponse processed = this.preprocessor .preprocess(createResponseWithContent( - "The uri 'http://localhost:12345' should be used")); + "The uri 'https://localhost:12345' should be used")); assertThat(new String(processed.getContent())) .isEqualTo("The uri 'https://api.example.com:12345' should be used"); } @@ -280,7 +280,7 @@ public class UriModifyingOperationPreprocessorTests { @Test public void urisInRequestHeadersCanBeModified() { OperationRequest processed = this.preprocessor.host("api.example.com") - .preprocess(createRequestWithHeader("Foo", "http://locahost:12345")); + .preprocess(createRequestWithHeader("Foo", "https://locahost:12345")); assertThat(processed.getHeaders().getFirst("Foo")) .isEqualTo("https://api.example.com:12345"); assertThat(processed.getHeaders().getFirst("Host")).isEqualTo("api.example.com"); @@ -289,7 +289,7 @@ public class UriModifyingOperationPreprocessorTests { @Test public void urisInResponseHeadersCanBeModified() { OperationResponse processed = this.preprocessor.host("api.example.com") - .preprocess(createResponseWithHeader("Foo", "http://locahost:12345")); + .preprocess(createResponseWithHeader("Foo", "https://locahost:12345")); assertThat(processed.getHeaders().getFirst("Foo")) .isEqualTo("https://api.example.com:12345"); } @@ -297,7 +297,7 @@ public class UriModifyingOperationPreprocessorTests { @Test public void urisInRequestPartHeadersCanBeModified() { OperationRequest processed = this.preprocessor.host("api.example.com").preprocess( - createRequestWithPartWithHeader("Foo", "http://locahost:12345")); + createRequestWithPartWithHeader("Foo", "https://locahost:12345")); assertThat(processed.getParts().iterator().next().getHeaders().getFirst("Foo")) .isEqualTo("https://api.example.com:12345"); } @@ -306,7 +306,7 @@ public class UriModifyingOperationPreprocessorTests { public void urisInRequestPartContentCanBeModified() { OperationRequest processed = this.preprocessor.host("api.example.com") .preprocess(createRequestWithPartWithContent( - "The uri 'http://localhost:12345' should be used")); + "The uri 'https://localhost:12345' should be used")); assertThat(new String(processed.getParts().iterator().next().getContent())) .isEqualTo("The uri 'https://api.example.com:12345' should be used"); }