Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

golint clean #94

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions cmd/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func testRFRCert(req *http.Request) (string, error) {

type TestCase struct {
ExpectAllow bool
OverTls bool
OverTLS bool
OverConnect bool
ProxyURL string
TargetPort int
Expand Down Expand Up @@ -176,7 +176,7 @@ func generateClientForTest(t *testing.T, test *TestCase) *http.Client {
if err != nil {
return nil, err
}
if test.OverTls {
if test.OverTLS {
var certs []tls.Certificate

if test.RoleName != "" {
Expand All @@ -198,11 +198,11 @@ func generateClientForTest(t *testing.T, test *TestCase) *http.Client {
caPool := x509.NewCertPool()
a.True(caPool.AppendCertsFromPEM(caBytes))

proxyTlsClientConfig := tls.Config{
proxyTLSClientConfig := tls.Config{
Certificates: certs,
RootCAs: caPool,
}
connRaw, err := tls.Dial("tcp", proxyURL.Host, &proxyTlsClientConfig)
connRaw, err := tls.Dial("tcp", proxyURL.Host, &proxyTLSClientConfig)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -251,7 +251,7 @@ func generateRequestForTest(t *testing.T, test *TestCase) *http.Request {
}
a.NoError(err)

if !test.OverTls && !test.OverConnect { // If we're not talking to the proxy over TLS, let's use headers as identifiers
if !test.OverTLS && !test.OverConnect { // If we're not talking to the proxy over TLS, let's use headers as identifiers
req.Header.Add("X-Smokescreen-Role", "egressneedingservice-"+test.RoleName)
req.Header.Add("X-Random-Trace", fmt.Sprintf("%d", test.RandomTrace))
}
Expand All @@ -278,24 +278,24 @@ func TestSmokescreenIntegration(t *testing.T) {

dummyServer := NewDummyServer()
outsideListener, err := net.Listen("tcp4", "127.0.0.1:")
outsideListenerUrl, err := url.Parse(fmt.Sprintf("http://%s", outsideListener.Addr().String()))
outsideListenerURL, err := url.Parse(fmt.Sprintf("http://%s", outsideListener.Addr().String()))
r.NoError(err)
outsideListenerPort, err := strconv.Atoi(outsideListenerUrl.Port())
outsideListenerPort, err := strconv.Atoi(outsideListenerURL.Port())
r.NoError(err)

go dummyServer.Serve(outsideListener)

var logHook logrustest.Hook
servers := map[bool]*httptest.Server{}
for _, useTls := range []bool{true, false} {
server, err := startSmokescreen(t, useTls, &logHook)
for _, useTLS := range []bool{true, false} {
server, err := startSmokescreen(t, useTLS, &logHook)
require.NoError(t, err)
defer server.Close()
servers[useTls] = server
servers[useTLS] = server
}

// Generate all non-tls tests
overTlsDomain := []bool{true, false}
overTLSDomain := []bool{true, false}
overConnectDomain := []bool{true, false}
authorizedHostsDomain := []bool{true, false}
actionsDomain := []acl.EnforcementPolicy{
Expand All @@ -307,8 +307,8 @@ func TestSmokescreenIntegration(t *testing.T) {
var testCases []*TestCase

for _, overConnect := range overConnectDomain {
for _, overTls := range overTlsDomain {
if overTls && !overConnect {
for _, overTLS := range overTLSDomain {
if overTLS && !overConnect {
// Is a super sketchy use case, let's not do that.
continue
}
Expand All @@ -324,9 +324,9 @@ func TestSmokescreenIntegration(t *testing.T) {
for _, action := range actionsDomain {
testCase := &TestCase{
ExpectAllow: authorizedHost || action != acl.Enforce,
OverTls: overTls,
OverTLS: overTLS,
OverConnect: overConnect,
ProxyURL: servers[overTls].URL,
ProxyURL: servers[overTLS].URL,
TargetPort: outsideListenerPort,
Host: host,
RoleName: generateRoleForAction(action),
Expand Down Expand Up @@ -376,7 +376,7 @@ func TestSmokescreenIntegration(t *testing.T) {
// this test will fail if we're not respecting the UpstreamProxy setting
// and instead going straight to this host.
proxyCase.Host = "aws.s3.amazonaws.com"
proxyCase.UpstreamProxy = outsideListenerUrl.String()
proxyCase.UpstreamProxy = outsideListenerURL.String()
proxyCase.ExpectAllow = true
proxyCase.RoleName = generateRoleForAction(acl.Open)

Expand Down Expand Up @@ -424,7 +424,7 @@ func findLogEntry(entries []*logrus.Entry, msg string) *logrus.Entry {
return nil
}

func startSmokescreen(t *testing.T, useTls bool, logHook logrus.Hook) (*httptest.Server, error) {
func startSmokescreen(t *testing.T, useTLS bool, logHook logrus.Hook) (*httptest.Server, error) {
args := []string{
"smokescreen",
"--listen-ip=127.0.0.1",
Expand All @@ -435,7 +435,7 @@ func startSmokescreen(t *testing.T, useTls bool, logHook logrus.Hook) (*httptest
"--deny-address=1.0.0.1:123",
}

if useTls {
if useTLS {
args = append(args,
"--tls-server-bundle-file=testdata/pki/server-bundle.pem",
"--tls-client-ca-file=testdata/pki/ca.pem",
Expand All @@ -448,7 +448,7 @@ func startSmokescreen(t *testing.T, useTls bool, logHook logrus.Hook) (*httptest
t.Fatalf("Failed to create configuration: %v", err)
}

if useTls {
if useTLS {
conf.RoleFromRequest = testRFRCert
} else {
conf.RoleFromRequest = testRFRHeader
Expand All @@ -460,7 +460,7 @@ func startSmokescreen(t *testing.T, useTls bool, logHook logrus.Hook) (*httptest
handler := smokescreen.BuildProxy(conf)
server := httptest.NewUnstartedServer(handler)

if useTls {
if useTLS {
server.TLS = conf.TlsConfig
server.StartTLS()
} else {
Expand Down
4 changes: 2 additions & 2 deletions cmd/smokescreen.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import (
"github.com/stripe/smokescreen/pkg/smokescreen/conntrack"
)

// Process command line args into a configuration object. If the "--help" or
// "--version" flags are provided, return nil with no error.
// NewConfiguration processes command line args into a configuration object.
// If the "--help" or "--version" flags are provided, return nil with no error.
// If args is nil, os.Args will be used. If logger is nil, a default logger
// will be created and included in the returned configuration.
func NewConfiguration(args []string, logger *log.Logger) (*smokescreen.Config, error) {
Expand Down