diff --git a/echo-notifications/src/main/groovy/com/netflix/spinnaker/echo/config/GithubConfig.java b/echo-notifications/src/main/groovy/com/netflix/spinnaker/echo/config/GithubConfig.java index fa110b9bb..56d791e86 100644 --- a/echo-notifications/src/main/groovy/com/netflix/spinnaker/echo/config/GithubConfig.java +++ b/echo-notifications/src/main/groovy/com/netflix/spinnaker/echo/config/GithubConfig.java @@ -52,7 +52,7 @@ public GithubService githubService( .setEndpoint(githubEndpoint) .setConverter(new JacksonConverter()) .setClient(retrofitClient) - .setLogLevel(RestAdapter.LogLevel.FULL) + .setLogLevel(retrofitLogLevel != null ? retrofitLogLevel : RestAdapter.LogLevel.BASIC) .setLog(new Slf4jRetrofitLogger(GithubService.class)) .build() .create(GithubService.class); diff --git a/echo-notifications/src/test/groovy/com/netflix/spinnaker/echo/config/GithubConfigSpec.groovy b/echo-notifications/src/test/groovy/com/netflix/spinnaker/echo/config/GithubConfigSpec.groovy index 99a2a995d..1f55faa42 100644 --- a/echo-notifications/src/test/groovy/com/netflix/spinnaker/echo/config/GithubConfigSpec.groovy +++ b/echo-notifications/src/test/groovy/com/netflix/spinnaker/echo/config/GithubConfigSpec.groovy @@ -3,6 +3,12 @@ package com.netflix.spinnaker.echo.config import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.test.context.SpringBootTest import retrofit.Endpoint +import retrofit.Endpoints +import retrofit.RestAdapter +import retrofit.client.Client +import retrofit.client.Header +import retrofit.client.Response +import retrofit.mime.TypedByteArray import spock.lang.Specification import spock.lang.Subject @@ -37,6 +43,79 @@ class GithubConfigSpec extends Specification { then: endpoint.url == ownEndpoint } + + + def 'default log level does not output authorization headers and matches basic API call structure'() { + given: + def systemError = System.out; + def testErr = new ByteArrayOutputStream(); + System.setOut(new PrintStream(testErr)) + + Client mockClient = Stub(Client) { + execute(_) >> { + return new Response("http://example.com", 200, "Success!", new ArrayList
(), new TypedByteArray("", "SOmething workedddd".bytes)) + } + + } + def ghService = new GithubConfig().githubService(Endpoints.newFixedEndpoint("http://example.com"), mockClient, null) + + when: + ghService.getCommit("SECRET", "repo-name", "sha12345"); + + then: + def logOutput = testErr.toString() + logOutput.contains("HTTP GET http://example.com/repos/repo-name/commits/sha12345") + !logOutput.contains("SECRET") + !logOutput.contains("Authorization") + + cleanup: + System.setOut(systemError) + System.out.print(testErr) + } + + def 'When no log set, no log output!'() { + given: + def systemError = System.out; + def testErr = new ByteArrayOutputStream(); + System.setOut(new PrintStream(testErr)) + + Client mockClient = Stub(Client) { + execute(_) >> new Response("http://example.com", 200, "Ok", new ArrayList
(), new TypedByteArray("", "response".bytes)) + } + def ghService = new GithubConfig().githubService(Endpoints.newFixedEndpoint("http://example.com"), mockClient, RestAdapter.LogLevel.NONE) + + when: + ghService.getCommit("", "", ""); + + then: + !testErr.toString().contains("GET") + + cleanup: + System.setOut(systemError) + System.out.print(testErr) + } + + def 'Log when full has header information and auth headers- dont do this in prod!'() { + given: + def systemError = System.out; + def testErr = new ByteArrayOutputStream(); + System.setOut(new PrintStream(testErr)) + + Client mockClient = Stub(Client) { + execute(_) >> new Response("http://example.com", 200, "Ok", new ArrayList
(), new TypedByteArray("", "response".bytes)) + } + def ghService = new GithubConfig().githubService(Endpoints.newFixedEndpoint("http://example.com"), mockClient, RestAdapter.LogLevel.FULL) + + when: + ghService.getCommit("", "", ""); + + then: + testErr.toString().contains("Authorization") + + cleanup: + System.setOut(systemError) + System.out.print(testErr) + } } @SpringBootTest(