aboutsummaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
authorNiall Sheridan <nsheridan@gmail.com>2016-07-10 22:35:13 +0100
committerNiall Sheridan <nsheridan@gmail.com>2016-07-17 13:58:10 +0100
commit49f40a952943f26494d6407dc608b50b2ec0df7f (patch)
treec261836adad0165642bb7ade18db78852ad6c5cb /server
parentdee5a19d36554a8f9a365efd65d13b134889bf63 (diff)
Add some handlers tests
Diffstat (limited to 'server')
-rw-r--r--server/auth/testprovider/testprovider.go56
-rw-r--r--server/signer/signer.go2
2 files changed, 57 insertions, 1 deletions
diff --git a/server/auth/testprovider/testprovider.go b/server/auth/testprovider/testprovider.go
new file mode 100644
index 0000000..3d2b13a
--- /dev/null
+++ b/server/auth/testprovider/testprovider.go
@@ -0,0 +1,56 @@
+package testprovider
+
+import (
+ "time"
+
+ "github.com/nsheridan/cashier/server/auth"
+
+ "golang.org/x/oauth2"
+)
+
+const (
+ name = "testprovider"
+)
+
+// Config is an implementation of `auth.Provider` for testing.
+type Config struct{}
+
+// New creates a new provider.
+func New() auth.Provider {
+ return &Config{}
+}
+
+// Name returns the name of the provider.
+func (c *Config) Name() string {
+ return name
+}
+
+// Valid validates the oauth token.
+func (c *Config) Valid(token *oauth2.Token) bool {
+ return true
+}
+
+// Revoke disables the access token.
+func (c *Config) Revoke(token *oauth2.Token) error {
+ return nil
+}
+
+// StartSession retrieves an authentication endpoint.
+func (c *Config) StartSession(state string) *auth.Session {
+ return &auth.Session{
+ AuthURL: "https://www.example.com/auth",
+ }
+}
+
+// Exchange authorizes the session and returns an access token.
+func (c *Config) Exchange(code string) (*oauth2.Token, error) {
+ return &oauth2.Token{
+ AccessToken: "token",
+ Expiry: time.Now().Add(1 * time.Hour),
+ }, nil
+}
+
+// Username retrieves the username portion of the user's email address.
+func (c *Config) Username(token *oauth2.Token) string {
+ return "test"
+}
diff --git a/server/signer/signer.go b/server/signer/signer.go
index a3f056a..8169c11 100644
--- a/server/signer/signer.go
+++ b/server/signer/signer.go
@@ -69,7 +69,7 @@ func makeperms(perms []string) map[string]string {
}
// New creates a new KeySigner from the supplied configuration.
-func New(conf config.SSH) (*KeySigner, error) {
+func New(conf *config.SSH) (*KeySigner, error) {
data, err := wkfs.ReadFile(conf.SigningKey)
if err != nil {
return nil, fmt.Errorf("unable to read CA key %s: %v", conf.SigningKey, err)