예제 #1
0
func TestWritingToAuditLogWhenDisabled(t *testing.T) {
	ctrl := gomock.NewController(t)
	defer ctrl.Finish()

	mockInfoLogger := mock_infologger.NewMockInfoLogger(ctrl)

	req, _ := http.NewRequest("GET", "foo", nil)

	cfg := &config.Config{
		Cluster:                     dummyCluster,
		CredentialsAuditLogFile:     "foo.txt",
		CredentialsAuditLogDisabled: true,
	}

	auditLogger := NewAuditLog(dummyContainerInstanceArn, cfg, mockInfoLogger)

	if auditLogger.GetCluster() != dummyCluster {
		t.Fatal("Cluster is not initialized properly")
	}

	if auditLogger.GetContainerInstanceArn() != dummyContainerInstanceArn {
		t.Fatal("ContainerInstanceArn is not initialized properly")
	}

	mockInfoLogger.EXPECT().Info(gomock.Any()).Times(0)

	auditLogger.Log(request.LogRequest{Request: req, ARN: taskARN}, dummyResponseCode, GetCredentialsEventType())
}
예제 #2
0
func TestWritingErrorsToAuditLog(t *testing.T) {
	ctrl := gomock.NewController(t)
	defer ctrl.Finish()

	mockInfoLogger := mock_infologger.NewMockInfoLogger(ctrl)

	req, _ := http.NewRequest("GET", "foo", nil)
	req.RemoteAddr = dummyRemoteAddress
	parsedUrl, err := url.Parse(dummyUrl)
	if err != nil {
		t.Fatal("error parsing dummyUrl")
	}
	req.URL = parsedUrl
	req.Header.Set("User-Agent", dummyUserAgent)

	cfg := &config.Config{
		Cluster:                 dummyCluster,
		CredentialsAuditLogFile: "foo.txt",
	}

	auditLogger := NewAuditLog(dummyContainerInstanceArn, cfg, mockInfoLogger)

	if auditLogger.GetCluster() != dummyCluster {
		t.Fatal("Cluster is not initialized properly")
	}

	if auditLogger.GetContainerInstanceArn() != dummyContainerInstanceArn {
		t.Fatal("ContainerInstanceArn is not initialized properly")
	}

	mockInfoLogger.EXPECT().Info(gomock.Any()).Do(func(logLine string) {
		tokens := strings.Split(logLine, " ")
		if len(tokens) != (commonAuditLogEntryFieldCount + getCredentialsEntryFieldCount) {

		}
		verifyAuditLogEntryResult(logLine, "-", t)
	})

	auditLogger.Log(request.LogRequest{Request: req, ARN: ""}, dummyResponseCode, GetCredentialsEventType())
}