func (s *signingKey) sign(t *testing.T, payload []byte) string {
	privKey := &jose.JSONWebKey{Key: s.priv, Algorithm: string(s.alg), KeyID: s.keyID}
	signer, err := jose.NewSigner(jose.SigningKey{Algorithm: s.alg, Key: privKey}, nil)
	if err != nil {
		t.Fatal(err)
	}
	jws, err := signer.Sign(payload)
	if err != nil {
		t.Fatal(err)
	}
	data, err := jws.CompactSerialize()
	if err != nil {
		t.Fatal(err)
	}
	return data
}
sign creates a JWS using the private key from the provided payload.
package main
import (
	"context"
	"crypto/rand"
	"crypto/rsa"
	"encoding/json"
	"fmt"
	"io/ioutil"
	"net"
	"net/http"
	"net/http/httptest"
	"net/url"
	"strconv"
	"strings"
	"testing"
	"time"
	oidc "github.com/coreos/go-oidc"
	"github.com/stretchr/testify/assert"
	"golang.org/x/oauth2"
	jose "gopkg.in/square/go-jose.v2"
	"github.com/uninett/goidc-proxy/conf"
)
var dummyConfig = oauth2.Config{
	ClientID:     "our-id",
	ClientSecret: "some-secret",
	Endpoint: oauth2.Endpoint{
		AuthURL:  "http://oauth.example.com/auth",
		TokenURL: "http://oauth.example.com/token",
	},
	RedirectURL: "http://localhost/oauth2/callback",
	Scopes:      []string{},
}
var dummyCookie = &http.Cookie{
	Name:   "test-cookie0",
	Value:  "dummy-token",
	MaxAge: 3600,
	Path:   "/",
}
var testStateID = "0000-1234-1337-9001"
var stateCookie = &http.Cookie{
	Name:   "state." + testStateID,
	Value:  "1234-1234-1234-1234",
	MaxAge: 3600,
	Path:   "/",
}
func testAuthHandler(t *testing.T) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		assert.True(t, true, "Nested handler called")
	})
}
func TestAuthHandlerRedirect(t *testing.T) {
	auth := &Authenticator{
		cookieName:   "test-cookie",
		signer:       NewSigner("test"),
		clientConfig: dummyConfig,
	}
	assert := assert.New(t)
	r := httptest.NewRequest("GET", "http://localhost/some_endpoint", nil)
	w := httptest.NewRecorder()
	ah := auth.authHandler(testAuthHandler(t))
	ah.ServeHTTP(w, r)
	assert.Equal(http.StatusForbidden, w.Code, "authHandler should return 403 Forbidden")
	locBytes, err := ioutil.ReadAll(w.Body)
	assert.Nil(err)
	loc := string(locBytes[:len(locBytes)])
	assert.True(strings.Contains(loc, dummyConfig.Endpoint.AuthURL+"?client_id="+dummyConfig.ClientID), "Redirect to correct URL")
}
type testVerifier struct {
	jwk jose.JSONWebKey
}
func (t *testVerifier) VerifySignature(ctx context.Context, jwt string) ([]byte, error) {
	jws, err := jose.ParseSigned(jwt)
	if err != nil {
		return nil, fmt.Errorf("oidc: malformed jwt: %v", err)
	}
	return jws.Verify(&t.jwk)
}
type signingKey struct {
	keyID string  
	priv  interface{}
	pub   interface{}
	alg   jose.SignatureAlgorithm
}