From bcbc7bc89a83f79d86b5c13438c8f04e581946b2 Mon Sep 17 00:00:00 2001 From: Jason McIntosh Date: Thu, 3 Aug 2023 15:36:43 -0500 Subject: [PATCH 1/2] fix(gha): Fix github status log and add tests --- .../spinnaker/echo/config/GithubConfig.java | 2 +- .../echo/config/GithubConfigSpec.groovy | 79 +++++++++++++++++++ 2 files changed, 80 insertions(+), 1 deletion(-) 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..6c854f819 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 'log level should not default to outputing authorization headers and match basci 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( From dc552bed7a1023bafff0a75195d0b1812cec8f53 Mon Sep 17 00:00:00 2001 From: Jason Date: Fri, 4 Aug 2023 08:48:06 -0500 Subject: [PATCH 2/2] chore(language): Update test message to be better Co-authored-by: David Byron <82477955+dbyron-sf@users.noreply.github.com> --- .../com/netflix/spinnaker/echo/config/GithubConfigSpec.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 6c854f819..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 @@ -45,7 +45,7 @@ class GithubConfigSpec extends Specification { } - def 'log level should not default to outputing authorization headers and match basci API call structure'() { + def 'default log level does not output authorization headers and matches basic API call structure'() { given: def systemError = System.out; def testErr = new ByteArrayOutputStream();