Skip to content

Commit

Permalink
Merge pull request #1 from ckaznocha/feature/travisDebug
Browse files Browse the repository at this point in the history
Added coveralls and changed case of auth header
  • Loading branch information
ckaznocha committed Mar 16, 2016
2 parents 70d0e80 + 5319043 commit 36f466b
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 14 deletions.
15 changes: 13 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
language: go

go:
- tip
- 1.4
- 1.5
- 1.6
- tip
env:
global:
secure: ulbX94oxaE9WonCN3/J3DK9vfnzNduvrBTnmnqxV2LU/WOCUvqwLVDM/5HAN1mBV82jalohbhVD3OI+FmjUrNfD9lic7ggKDUohdTjQaasF4AJG6XYyFQf4yRP07mZRa0kqnjNMXL1Ya7QJXdf7bEbxeD0NrBa1JAd5YuUcSfQI+FoNOvOqPfo7ndp6cggGSfn8J/pquR/2NbAN/mVf9X9zaMkBsbV0LT6S78E1/YGk3psKW39cNtYg1bXj4vrO3vQwksdfHQmhzOYzFLJh/QoQuux5mGTvrpYcspWWejsB+xmJQXaR8gIkRbYtXE0WDCcQL9g5MZCrIuk5g1EESMS8pcqRE3zB+NSAHuEYWPHh1J3fLNgLko76Cku49zaDDP/pO4QCg4g+Qz4Wfof1FnhhEGYMYJajNhDNtdE89FTYu8W5MYJzcPSxedljn3Dv1gVdoCXPtj9secJk79pIS2yjGLjuPXSQTEo/IBL4Gq25ilEJsSGflLdWvBKwQkeqp7Wzi6zWoHRVDiB7q+3LqGHyWo4V9p+IUCVHTUiQFpf5fQYWEyxLRz6M4z/J8P2jCiWgpaYekUoGHxK0znjuclfoLu6fipyQbsMY7AgjEWwOf3OK408d3nsRJTJsDeKFz880AOcjXA9+z8K0J/5mPa2mF73adeTTyNSnYCyO2oec=
before_install:
- go get github.com/mattn/goveralls
- go get golang.org/x/tools/cmd/cover
script:
- go test -v -race -cpu 1,4 -covermode=count -coverprofile=profile.cov ./
- goveralls -coverprofile=profile.cov -service=travis-ci
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# bearerware

[![Build Status](http://img.shields.io/travis/ckaznocha/go-JWTBearerware.svg?style=flat)](https://travis-ci.org/ckaznocha/go-JWTBearerware)
[![Coverage Status](https://coveralls.io/repos/github/ckaznocha/go-JWTBearerware/badge.svg?branch=master)](https://coveralls.io/github/ckaznocha/go-JWTBearerware?branch=master)
[![License](http://img.shields.io/:license-mit-blue.svg)](http://ckaznocha.mit-license.org)
[![GoDoc](https://godoc.org/github.com/ckaznocha/go-JWTBearerware?status.svg)](https://godoc.org/github.com/ckaznocha/go-JWTBearerware)
[![Go Report Card](https://goreportcard.com/badge/ckaznocha/go-JWTBearerware)](https://goreportcard.com/report/ckaznocha/go-JWTBearerware)
Expand Down Expand Up @@ -52,7 +53,7 @@ gRPC requests.
```go
func WriteAuthError(w http.ResponseWriter, err error)
```
WriteAuthError is a convienence functon for setting the WWW-Authenticate header
WriteAuthError is a convenience function for setting the WWW-Authenticate header
and sending an http.Error()

#### type JWTContexter
Expand Down
2 changes: 1 addition & 1 deletion bearerware.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

const (
authHeader = "Authorization"
authHeader = "authorization"
bearer = "bearer "
bearerLen = len(bearer)

Expand Down
5 changes: 3 additions & 2 deletions example_gRPC_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
const (
certFile = "./test_cert/server.pem"
keyFile = "./test_cert/server.key"
host = "localhost"
host = "127.0.0.1"
port = "50051"
netString = "tcp"
)
Expand Down Expand Up @@ -72,7 +72,7 @@ func Example_gRPC() {

// Set up a connection to the server using TLS and a JWT
var (
tlsCreds, _ = credentials.NewClientTLSFromFile(certFile, host)
tlsCreds, _ = credentials.NewClientTLSFromFile(certFile, "localhost")
//Create a JWT for the example
tokenString, _ = jwt.New(signingMethod).SignedString(jwtKey)
jwtCreds, _ = bearerware.NewJWTAccessFromJWT(tokenString)
Expand All @@ -82,6 +82,7 @@ func Example_gRPC() {
//included in every request.
grpc.WithPerRPCCredentials(jwtCreds),
grpc.WithTimeout(5 * time.Second),
grpc.WithBlock(),
}
)
conn, err := grpc.Dial(net.JoinHostPort(host, port), dialOpts...)
Expand Down
5 changes: 2 additions & 3 deletions gRPC.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package bearerware

import (
"fmt"
"net/http"
"strings"

"github.com/dgrijalva/jwt-go"
Expand All @@ -25,7 +24,7 @@ func NewJWTAccessFromJWT(jsonKey string) (credentials.Credentials, error) {

func (j jwtAccess) GetRequestMetadata(ctx context.Context, uri ...string) (map[string]string, error) {
return map[string]string{
http.CanonicalHeaderKey(authHeader): fmt.Sprintf("%s%s", strings.Title(bearer), j.jsonKey),
authHeader: fmt.Sprintf("%s%s", strings.Title(bearer), j.jsonKey),
}, nil
}

Expand All @@ -47,7 +46,7 @@ func JWTFromContext(
}
var tokenStrings []string
for k := range md {
if http.CanonicalHeaderKey(authHeader) == http.CanonicalHeaderKey(k) {
if authHeader == k {
tokenStrings = md[k]
break
}
Expand Down
7 changes: 3 additions & 4 deletions gRPC_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package bearerware

import (
"errors"
"net/http"
"reflect"
"testing"

Expand All @@ -20,7 +19,7 @@ func TestJWTAccessCredentials(t *testing.T) {
}{
{
token: "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiIiLCJpYXQiOm51bGwsImV4cCI6bnVsbCwiYXVkIjoiIiwic3ViIjoiIn0.IlffGJz3IyFX1ADQ6-jOTQ_0D-K0kuKq5SpB_oirCrk",
md: map[string]string{http.CanonicalHeaderKey(authHeader): "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiIiLCJpYXQiOm51bGwsImV4cCI6bnVsbCwiYXVkIjoiIiwic3ViIjoiIn0.IlffGJz3IyFX1ADQ6-jOTQ_0D-K0kuKq5SpB_oirCrk"},
md: map[string]string{authHeader: "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiIiLCJpYXQiOm51bGwsImV4cCI6bnVsbCwiYXVkIjoiIiwic3ViIjoiIn0.IlffGJz3IyFX1ADQ6-jOTQ_0D-K0kuKq5SpB_oirCrk"},
},
}
for _, test := range tests {
Expand Down Expand Up @@ -56,7 +55,7 @@ func TestJWTFromContext(t *testing.T) {
{
ctx: metadata.NewContext(
context.Background(),
metadata.New(map[string]string{http.CanonicalHeaderKey(authHeader): "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiIiLCJpYXQiOm51bGwsImV4cCI6bnVsbCwiYXVkIjoiIiwic3ViIjoiIn0.IlffGJz3IyFX1ADQ6-jOTQ_0D-K0kuKq5SpB_oirCrk"}),
metadata.New(map[string]string{authHeader: "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiIiLCJpYXQiOm51bGwsImV4cCI6bnVsbCwiYXVkIjoiIiwic3ViIjoiIn0.IlffGJz3IyFX1ADQ6-jOTQ_0D-K0kuKq5SpB_oirCrk"}),
),
signingMethod: jwt.SigningMethodHS256,
err: nil,
Expand All @@ -77,7 +76,7 @@ func TestJWTFromContext(t *testing.T) {
{
ctx: metadata.NewContext(
context.Background(),
metadata.New(map[string]string{http.CanonicalHeaderKey(authHeader): "Beare eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiIiLCJpYXQiOm51bGwsImV4cCI6bnVsbCwiYXVkIjoiIiwic3ViIjoiIn0.IlffGJz3IyFX1ADQ6-jOTQ_0D-K0kuKq5SpB_oirCrk"}),
metadata.New(map[string]string{authHeader: "Beare eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiIiLCJpYXQiOm51bGwsImV4cCI6bnVsbCwiYXVkIjoiIiwic3ViIjoiIn0.IlffGJz3IyFX1ADQ6-jOTQ_0D-K0kuKq5SpB_oirCrk"}),
),
signingMethod: jwt.SigningMethodHS256,
err: errors.New("Authorization header format must be Bearer {token}"),
Expand Down
2 changes: 1 addition & 1 deletion http.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func JWTFromHeader(
}

/*
WriteAuthError is a convienence functon for setting the WWW-Authenticate header
WriteAuthError is a convenience function for setting the WWW-Authenticate header
and sending an http.Error()
*/
func WriteAuthError(w http.ResponseWriter, err error) {
Expand Down

0 comments on commit 36f466b

Please sign in to comment.