fix coverage (#1741)

* fix coverage

* fix data races
This commit is contained in:
Caleb Doxsey 2021-01-06 08:30:38 -07:00 committed by GitHub
parent 6ea8d34b8f
commit 4f0ce4bc82
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 18 additions and 21 deletions

View file

@ -102,14 +102,8 @@ spellcheck: # Spellcheck docs
.PHONY: cover .PHONY: cover
cover: ## Runs go test with coverage cover: ## Runs go test with coverage
@echo "" > coverage.txt @echo "==> $@"
@for d in $(shell go list ./... | grep -v vendor); do \ $(GO) test -race -coverprofile=coverage.txt -tags "$(BUILDTAGS)" $(shell $(GO) list ./... | grep -v vendor | grep -v github.com/pomerium/pomerium/integration)
$(GO) test -race -coverprofile=profile.out -covermode=atomic "$$d"; \
if [ -f profile.out ]; then \
cat profile.out >> coverage.txt; \
rm profile.out; \
fi; \
done;
.PHONY: clean .PHONY: clean
clean: ## Cleanup any build binaries or packages. clean: ## Cleanup any build binaries or packages.

View file

@ -224,27 +224,30 @@ func (e *Evaluator) JWTPayload(req *Request) map[string]interface{} {
} }
func newSigner(options *config.Options) (jose.Signer, *jose.JSONWebKey, error) { func newSigner(options *config.Options) (jose.Signer, *jose.JSONWebKey, error) {
var decodedCert []byte
// if we don't have a signing key, generate one // if we don't have a signing key, generate one
if options.SigningKey == "" { if options.SigningKey == "" {
key, err := cryptutil.NewSigningKey() key, err := cryptutil.NewSigningKey()
if err != nil { if err != nil {
return nil, nil, fmt.Errorf("couldn't generate signing key: %w", err) return nil, nil, fmt.Errorf("couldn't generate signing key: %w", err)
} }
generatedKey, err := cryptutil.EncodePrivateKey(key) decodedCert, err = cryptutil.EncodePrivateKey(key)
if err != nil { if err != nil {
return nil, nil, fmt.Errorf("bad signing key: %w", err) return nil, nil, fmt.Errorf("bad signing key: %w", err)
} }
options.SigningKey = base64.StdEncoding.EncodeToString(generatedKey) } else {
var err error
decodedCert, err = base64.StdEncoding.DecodeString(options.SigningKey)
if err != nil {
return nil, nil, fmt.Errorf("bad signing key: %w", err)
} }
if options.SigningKeyAlgorithm == "" { }
options.SigningKeyAlgorithm = string(jose.ES256) signingKeyAlgorithm := options.SigningKeyAlgorithm
if signingKeyAlgorithm == "" {
signingKeyAlgorithm = string(jose.ES256)
} }
decodedCert, err := base64.StdEncoding.DecodeString(options.SigningKey) jwk, err := cryptutil.PrivateJWKFromBytes(decodedCert, jose.SignatureAlgorithm(signingKeyAlgorithm))
if err != nil {
return nil, nil, fmt.Errorf("bad signing key: %w", err)
}
jwk, err := cryptutil.PrivateJWKFromBytes(decodedCert, jose.SignatureAlgorithm(options.SigningKeyAlgorithm))
if err != nil { if err != nil {
return nil, nil, fmt.Errorf("couldn't generate signing key: %w", err) return nil, nil, fmt.Errorf("couldn't generate signing key: %w", err)
} }

View file

@ -212,7 +212,6 @@ func Test_Checksum(t *testing.T) {
} }
func TestOptionsFromViper(t *testing.T) { func TestOptionsFromViper(t *testing.T) {
t.Parallel()
opts := []cmp.Option{ opts := []cmp.Option{
cmpopts.IgnoreFields(Options{}, "CookieSecret", "GRPCInsecure", "GRPCAddr", "DataBrokerURLString", "DataBrokerURL", "AuthorizeURL", "AuthorizeURLString", "DefaultUpstreamTimeout", "CookieExpire", "Services", "Addr", "RefreshCooldown", "LogLevel", "KeyFile", "CertFile", "SharedKey", "ReadTimeout", "IdleTimeout", "GRPCClientTimeout", "GRPCClientDNSRoundRobin", "TracingSampleRate"), cmpopts.IgnoreFields(Options{}, "CookieSecret", "GRPCInsecure", "GRPCAddr", "DataBrokerURLString", "DataBrokerURL", "AuthorizeURL", "AuthorizeURLString", "DefaultUpstreamTimeout", "CookieExpire", "Services", "Addr", "RefreshCooldown", "LogLevel", "KeyFile", "CertFile", "SharedKey", "ReadTimeout", "IdleTimeout", "GRPCClientTimeout", "GRPCClientDNSRoundRobin", "TracingSampleRate"),
cmpopts.IgnoreFields(Policy{}, "Source", "Destination"), cmpopts.IgnoreFields(Policy{}, "Source", "Destination"),

View file

@ -196,8 +196,9 @@ func (tun *Tunnel) run(ctx context.Context, local io.ReadWriter, rawJWT string,
_, err := io.Copy(remote, local) _, err := io.Copy(remote, local)
errc <- err errc <- err
}() }()
remoteReader := deBuffer(br, remote)
go func() { go func() {
_, err := io.Copy(local, deBuffer(br, remote)) _, err := io.Copy(local, remoteReader)
errc <- err errc <- err
}() }()

View file

@ -91,7 +91,7 @@ func TestGetGRPC(t *testing.T) {
return return
} }
assert.Equal(t, cc1, cc2, "GetGRPCClientConn should return the same connection when there are no changes") assert.Same(t, cc1, cc2, "GetGRPCClientConn should return the same connection when there are no changes")
cc3, err := GetGRPCClientConn("example", &Options{ cc3, err := GetGRPCClientConn("example", &Options{
Addr: mustParseURL("http://localhost.example"), Addr: mustParseURL("http://localhost.example"),
@ -101,7 +101,7 @@ func TestGetGRPC(t *testing.T) {
return return
} }
assert.NotEqual(t, cc1, cc3, "GetGRPCClientConn should return a new connection when there are changes") assert.NotSame(t, cc1, cc3, "GetGRPCClientConn should return a new connection when there are changes")
} }
func mustParseURL(rawurl string) *url.URL { func mustParseURL(rawurl string) *url.URL {