[ARVADOS-ORG] updated: f489600b784c735e7d8057b5fc28b9748941cd67
Git user
git at public.curoverse.com
Tue May 16 21:45:22 EDT 2017
Summary of changes:
discards 4338e180bb7182ac1e7080eef5b8c90fd2cfb0a9 (commit)
via f489600b784c735e7d8057b5fc28b9748941cd67 (commit)
This update added new revisions after undoing existing revisions. That is
to say, the old revision is not a strict subset of the new revision. This
situation occurs when you --force push a change and generate a repository
containing something like this:
* -- * -- B -- O -- O -- O (4338e180bb7182ac1e7080eef5b8c90fd2cfb0a9)
\
N -- N -- N (f489600b784c735e7d8057b5fc28b9748941cd67)
When this happens we assume that you've already had alert emails for all
of the O revisions, and so we here report only the revisions in the N
branch from the common base, B.
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
commit f489600b784c735e7d8057b5fc28b9748941cd67
Author: Ward Vandewege <ward at curoverse.com>
Date: Tue May 16 21:41:25 2017 -0400
got fmt fixes.
Arvados-DCO-1.1-Signed-off-by: Ward Vandewege <ward at curoverse.com>
diff --git a/registry/cmd/arv-registry/arv-registry.go b/registry/cmd/arv-registry/arv-registry.go
index f360525..7b03a52 100644
--- a/registry/cmd/arv-registry/arv-registry.go
+++ b/registry/cmd/arv-registry/arv-registry.go
@@ -8,8 +8,9 @@ import (
"bufio"
"flag"
"fmt"
- "git.curoverse.com/arvados-org.git/registry"
"os"
+
+ "git.curoverse.com/arvados-org.git/registry"
)
var theCluster registry.ClusterInfo
diff --git a/registry/server/registryd/registryd.go b/registry/server/registryd/registryd.go
index e997a89..e53f2ef 100644
--- a/registry/server/registryd/registryd.go
+++ b/registry/server/registryd/registryd.go
@@ -9,22 +9,23 @@ import (
"flag"
"fmt"
- "git.curoverse.com/arvados-org.git/registry"
+ "git.curoverse.com/arvados-org.git/registry"
- "net"
- "net/http"
- "os"
- "os/signal"
"crypto/hmac"
"crypto/sha256"
"database/sql"
"encoding/base64"
- _ "github.com/mattn/go-sqlite3"
- "github.com/rubenv/sql-migrate"
+ "net"
+ "net/http"
+ "os"
+ "os/signal"
"regexp"
"strings"
"syscall"
"time"
+
+ _ "github.com/mattn/go-sqlite3"
+ "github.com/rubenv/sql-migrate"
)
var listener net.Listener
@@ -185,14 +186,14 @@ func registerHandler(w http.ResponseWriter, r *http.Request) {
return
}
- if cluster.Name == "" ||
- cluster.Email == "" ||
- cluster.Organization == "" {
+ if cluster.Name == "" ||
+ cluster.Email == "" ||
+ cluster.Organization == "" {
errReport = registry.Report{"Error", "Missing fields: name, email, organization are required"}
w.WriteHeader(http.StatusBadRequest)
registry.MarshalAndWrite(w, errReport)
return
- }
+ }
match, err := regexp.MatchString("^.+ at .+\\..+$", cluster.Email)
if err != nil {
@@ -205,7 +206,7 @@ func registerHandler(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusBadRequest)
registry.MarshalAndWrite(w, errReport)
return
- }
+ }
logCluster := cluster
logCluster.ClientSecret = "" // So as not to log it
@@ -213,7 +214,7 @@ func registerHandler(w http.ResponseWriter, r *http.Request) {
registry.LogNotice([]string{"Received valid JSON request body:", string(encoded)})
var available, registered bool
- var registeredOn time.Time
+ var registeredOn time.Time
var data map[string]string
available, registered, registeredOn, data, _, err = lookup(clusterID)
@@ -225,14 +226,14 @@ func registerHandler(w http.ResponseWriter, r *http.Request) {
}
if available {
- // Cf. https://en.wikipedia.org/wiki/X-Forwarded-For#Format
- ipAddress := strings.Split(r.Header.Get("X-Forwarded-For"), ", ")[0]
- if ipAddress == "" {
- ipAddress, _, err = net.SplitHostPort(r.RemoteAddr)
- if err != nil {
- fmt.Fprintf(w, "userip: %q is not IP:port", r.RemoteAddr)
- }
- }
+ // Cf. https://en.wikipedia.org/wiki/X-Forwarded-For#Format
+ ipAddress := strings.Split(r.Header.Get("X-Forwarded-For"), ", ")[0]
+ if ipAddress == "" {
+ ipAddress, _, err = net.SplitHostPort(r.RemoteAddr)
+ if err != nil {
+ fmt.Fprintf(w, "userip: %q is not IP:port", r.RemoteAddr)
+ }
+ }
// register it
err := register(clusterID, cluster, ipAddress)
if err != nil {
@@ -265,7 +266,7 @@ func checkHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json; charset=utf-8")
var available, registered, requestAuthenticated bool
- var registeredOn time.Time
+ var registeredOn time.Time
var data map[string]string
clusterID, errReport := sanityCheckClusterID(r.URL.Path[10:])
@@ -278,9 +279,9 @@ func checkHandler(w http.ResponseWriter, r *http.Request) {
return
}
- // This ClusterID did not pass the sanity check, it is invalid
+ // This ClusterID did not pass the sanity check, it is invalid
if errReport != (registry.Report{}) {
- available = false
+ available = false
}
// An optional request body is permitted to send a ClientSecret
@@ -298,10 +299,10 @@ func checkHandler(w http.ResponseWriter, r *http.Request) {
}
}
}
- registeredOnPtr := ®isteredOn
- if registered == false {
- registeredOnPtr = nil
- }
+ registeredOnPtr := ®isteredOn
+ if registered == false {
+ registeredOnPtr = nil
+ }
m := result{clusterID, available, registered, registeredOnPtr, data, requestAuthenticated, fmt.Sprintf("%v", time.Since(start))}
registry.MarshalAndWrite(w, m)
diff --git a/registry/server/registryd/registryd_test.go b/registry/server/registryd/registryd_test.go
index d7b11db..7348285 100644
--- a/registry/server/registryd/registryd_test.go
+++ b/registry/server/registryd/registryd_test.go
@@ -5,16 +5,17 @@
package main
import (
- "bytes"
- "fmt"
- "git.curoverse.com/arvados-org.git/registry"
- . "gopkg.in/check.v1"
- "io/ioutil"
- "log"
- "net/http"
- "os"
- "testing"
- "time"
+ "bytes"
+ "fmt"
+ "io/ioutil"
+ "log"
+ "net/http"
+ "os"
+ "testing"
+ "time"
+
+ "git.curoverse.com/arvados-org.git/registry"
+ . "gopkg.in/check.v1"
)
// Hook gocheck into the "go test" runner.
@@ -31,289 +32,289 @@ var tmpConfigFileName string
var tmpDBFileName string
func closeListener() {
- if listener != nil {
- listener.Close()
- }
+ if listener != nil {
+ listener.Close()
+ }
}
func (s *ServerNotRequiredSuite) TestConfig(c *C) {
- var config Config
+ var config Config
- // A specified but non-existing config path needs to result in an error
- err := registry.ReadConfig(&config, "/nosuchdir89j7879/8hjwr7ojgyy7", defaultConfigPath)
- c.Assert(err, NotNil)
+ // A specified but non-existing config path needs to result in an error
+ err := registry.ReadConfig(&config, "/nosuchdir89j7879/8hjwr7ojgyy7", defaultConfigPath)
+ c.Assert(err, NotNil)
- // No configuration file and default configuration path specified, must error
- err = registry.ReadConfig(&config, "/nosuchdir89j7879/8hjwr7ojgyy7", "/nosuchdir89j7879/8hjwr7ojgyy7")
- c.Assert(err, NotNil)
+ // No configuration file and default configuration path specified, must error
+ err = registry.ReadConfig(&config, "/nosuchdir89j7879/8hjwr7ojgyy7", "/nosuchdir89j7879/8hjwr7ojgyy7")
+ c.Assert(err, NotNil)
- // Test parsing of config data
- tmpfile, err := ioutil.TempFile(os.TempDir(), "config")
- c.Check(err, IsNil)
- defer os.Remove(tmpfile.Name())
+ // Test parsing of config data
+ tmpfile, err := ioutil.TempFile(os.TempDir(), "config")
+ c.Check(err, IsNil)
+ defer os.Remove(tmpfile.Name())
- tmpdb, err := ioutil.TempFile(os.TempDir(), "db")
- c.Check(err, IsNil)
- defer os.Remove(tmpdb.Name())
+ tmpdb, err := ioutil.TempFile(os.TempDir(), "db")
+ c.Check(err, IsNil)
+ defer os.Remove(tmpdb.Name())
- argsS := `{"ServerSecret": "super_secret_sauce", "ListenPort": "12345", "Database": "` + tmpdb.Name() + `"}`
- _, err = tmpfile.Write([]byte(argsS))
- c.Check(err, IsNil)
+ argsS := `{"ServerSecret": "super_secret_sauce", "ListenPort": "12345", "Database": "` + tmpdb.Name() + `"}`
+ _, err = tmpfile.Write([]byte(argsS))
+ c.Check(err, IsNil)
- err = registry.ReadConfig(&config, tmpfile.Name(), defaultConfigPath)
- c.Assert(err, IsNil)
+ err = registry.ReadConfig(&config, tmpfile.Name(), defaultConfigPath)
+ c.Assert(err, IsNil)
- c.Check(config.ServerSecret, Equals, "super_secret_sauce")
- c.Check(config.ListenPort, Equals, "12345")
- c.Check(config.Database, Equals, tmpdb.Name())
+ c.Check(config.ServerSecret, Equals, "super_secret_sauce")
+ c.Check(config.ListenPort, Equals, "12345")
+ c.Check(config.Database, Equals, tmpdb.Name())
}
func (s *ServerNotRequiredSuite) TestFlags(c *C) {
- args := []string{"arvados-cluster-registry"}
- os.Args = append(args)
+ args := []string{"arvados-cluster-registry"}
+ os.Args = append(args)
}
func runServer(c *C) {
- tmpfile, err := ioutil.TempFile(os.TempDir(), "config")
- c.Check(err, IsNil)
+ tmpfile, err := ioutil.TempFile(os.TempDir(), "config")
+ c.Check(err, IsNil)
- tmpConfigFileName = tmpfile.Name()
+ tmpConfigFileName = tmpfile.Name()
- tmpdb, err := ioutil.TempFile(os.TempDir(), "db")
- c.Check(err, IsNil)
+ tmpdb, err := ioutil.TempFile(os.TempDir(), "db")
+ c.Check(err, IsNil)
- tmpDBFileName = tmpdb.Name()
+ tmpDBFileName = tmpdb.Name()
- argsS := `{"ServerSecret": "a_very_good_secret_this_is_not", "ListenPort": "12345", "Database": ` + tmpDBFileName + `}`
- _, err = tmpfile.Write([]byte(argsS))
- c.Check(err, IsNil)
+ argsS := `{"ServerSecret": "a_very_good_secret_this_is_not", "ListenPort": "12345", "Database": ` + tmpDBFileName + `}`
+ _, err = tmpfile.Write([]byte(argsS))
+ c.Check(err, IsNil)
- args := []string{"arvados-cluster-registry"}
- os.Args = append(args, "-config", tmpfile.Name())
- listener = nil
- go main()
- waitForListener()
+ args := []string{"arvados-cluster-registry"}
+ os.Args = append(args, "-config", tmpfile.Name())
+ listener = nil
+ go main()
+ waitForListener()
}
func waitForListener() {
- const (
- ms = 5
- )
- for i := 0; listener == nil && i < 10000; i += ms {
- time.Sleep(ms * time.Millisecond)
- }
- if listener == nil {
- log.Fatalf("Timed out waiting for listener to start")
- }
+ const (
+ ms = 5
+ )
+ for i := 0; listener == nil && i < 10000; i += ms {
+ time.Sleep(ms * time.Millisecond)
+ }
+ if listener == nil {
+ log.Fatalf("Timed out waiting for listener to start")
+ }
}
func (s *ServerNotRequiredSuite) SetUpTest(c *C) {
- // Discard standard log output
- log.SetOutput(ioutil.Discard)
+ // Discard standard log output
+ log.SetOutput(ioutil.Discard)
}
func (s *ServerRequiredSuite) SetUpTest(c *C) {
- // Discard standard log output
- log.SetOutput(ioutil.Discard)
+ // Discard standard log output
+ log.SetOutput(ioutil.Discard)
}
func (s *ServerRequiredSuite) TearDownSuite(c *C) {
- log.SetOutput(os.Stderr)
+ log.SetOutput(os.Stderr)
}
func (s *ServerNotRequiredSuite) TearDownSuite(c *C) {
- log.SetOutput(os.Stderr)
+ log.SetOutput(os.Stderr)
}
func (s *ServerRequiredSuite) TestResults(c *C) {
- runServer(c)
- defer closeListener()
- defer os.Remove(tmpDBFileName)
- defer os.Remove(tmpConfigFileName)
-
- // Test the about handler
- {
- client := http.Client{}
- req, err := http.NewRequest("GET",
- fmt.Sprintf("http://%s/%s", listener.Addr().String(), "v1/about"),
- nil)
- resp, err := client.Do(req)
- c.Check(err, Equals, nil)
- c.Check(resp.StatusCode, Equals, 200)
- body, err := ioutil.ReadAll(resp.Body)
- c.Check(string(body), Matches, ".*\"Name\":\"Arvados Registry Daemon\".*")
- }
-
- // Test the help handler
- {
- client := http.Client{}
- req, err := http.NewRequest("GET",
- fmt.Sprintf("http://%s/%s", listener.Addr().String(), "v1/help"),
- nil)
- resp, err := client.Do(req)
- c.Check(err, Equals, nil)
- c.Check(resp.StatusCode, Equals, 200)
- body, err := ioutil.ReadAll(resp.Body)
- c.Check(string(body), Matches, ".*GET /v1/about or GET /v1/help.*")
- }
-
- // Registration of a valid ClusterID with proper JSON body (must pass)
- {
- client := http.Client{}
- var jsonStr = []byte(`{"clientSecret":"this_is_long_enough","name":"Ward Vandewege","email":"sysadmin at curoverse.com","organization":"Curoverse, Inc."}`)
- req, err := http.NewRequest("POST",
- fmt.Sprintf("http://%s/%s", listener.Addr().String(), "v1/register/abcde"),
- bytes.NewBuffer(jsonStr))
- resp, err := client.Do(req)
- c.Check(err, Equals, nil)
- c.Check(resp.StatusCode, Equals, 200)
- body, err := ioutil.ReadAll(resp.Body)
- c.Check(string(body), Matches, ".*\"ClusterID\":\"abcde\",\"Available\":false,\"Registered\":true.*")
- }
-
- // Check existence of a valid ClusterID (must pass)
- {
- client := http.Client{}
- req, err := http.NewRequest("GET",
- fmt.Sprintf("http://%s/%s", listener.Addr().String(), "v1/check/abcde"),
- nil)
- resp, err := client.Do(req)
- c.Check(err, Equals, nil)
- c.Check(resp.StatusCode, Equals, 200)
- body, err := ioutil.ReadAll(resp.Body)
- c.Check(string(body), Matches, ".*\"ClusterID\":\"abcde\",\"Available\":false,\"Registered\":true.*")
- }
-
- // Check existence of an invalid ClusterID (must pass)
- {
- client := http.Client{}
- req, err := http.NewRequest("GET",
- fmt.Sprintf("http://%s/%s", listener.Addr().String(), "v1/check/1bcde"),
- nil)
- resp, err := client.Do(req)
- c.Check(err, Equals, nil)
- c.Check(resp.StatusCode, Equals, 200)
- body, err := ioutil.ReadAll(resp.Body)
- c.Check(string(body), Matches, ".*\"ClusterID\":\"1bcde\",\"Available\":false,\"Registered\":false.*")
- }
-
- // Registration of a ClusterID with proper JSON body missing fields (must fail)
- {
- client := http.Client{}
- var jsonStr = []byte(`{"clientSecret":"this_is_long_enough"}`)
- req, err := http.NewRequest("POST",
- fmt.Sprintf("http://%s/%s", listener.Addr().String(), "v1/register/abcde"),
- bytes.NewBuffer(jsonStr))
- resp, err := client.Do(req)
- c.Check(err, Equals, nil)
- c.Check(resp.StatusCode, Equals, 400)
- body, err := ioutil.ReadAll(resp.Body)
- c.Check(string(body), Matches, ".*Missing fields.*")
- }
-
- // Registration of an existing ClusterID with proper JSON body (must fail)
- {
- client := http.Client{}
- var jsonStr = []byte(`{"clientSecret":"this_is_long_enough","name":"Ward Vandewege","email":"sysadmin at curoverse.com","organization":"Curoverse, Inc."}`)
- req, err := http.NewRequest("POST",
- fmt.Sprintf("http://%s/%s", listener.Addr().String(), "v1/register/abcde"),
- bytes.NewBuffer(jsonStr))
- resp, err := client.Do(req)
- c.Check(err, Equals, nil)
- c.Check(resp.StatusCode, Equals, 400)
- body, err := ioutil.ReadAll(resp.Body)
- c.Check(string(body), Matches, ".*This ClusterID is not available for registration.*")
- }
-
- // Registration of a valid ClusterID with proper JSON body but clientSecret that is too short (must fail)
- {
- client := http.Client{}
- var jsonStr = []byte(`{"clientSecret":"not_long_enough"}`)
- req, err := http.NewRequest("POST",
- fmt.Sprintf("http://%s/%s", listener.Addr().String(), "v1/register/abcde"),
- bytes.NewBuffer(jsonStr))
- resp, err := client.Do(req)
- c.Check(err, Equals, nil)
- c.Check(resp.StatusCode, Equals, 400)
- body, err := ioutil.ReadAll(resp.Body)
- c.Check(string(body), Matches, ".*min length: 16 characters.*")
- }
-
- // Registration of a valid ClusterID but without JSON body (must fail)
- {
- client := http.Client{}
- req, err := http.NewRequest("POST",
- fmt.Sprintf("http://%s/%s", listener.Addr().String(), "v1/register/abcde"),
- nil)
- resp, err := client.Do(req)
- c.Check(err, Equals, nil)
- c.Check(resp.StatusCode, Equals, 400)
- body, err := ioutil.ReadAll(resp.Body)
- c.Check(string(body), Matches, ".*Unable to decode request body as JSON.*")
- }
-
- // Registration of an invalid ClusterID (must fail)
- {
- client := http.Client{}
- req, err := http.NewRequest("POST",
- fmt.Sprintf("http://%s/%s", listener.Addr().String(), "v1/register/1abcd"),
- nil)
- resp, err := client.Do(req)
- c.Check(err, Equals, nil)
- c.Check(resp.StatusCode, Equals, 400)
- body, err := ioutil.ReadAll(resp.Body)
- c.Check(string(body), Matches, ".*Invalid ClusterID.*")
- }
-
- // Registration of an invalid ClusterID (must fail)
- {
- client := http.Client{}
- req, err := http.NewRequest("POST",
- fmt.Sprintf("http://%s/%s", listener.Addr().String(), "v1/register/xabcd"),
- nil)
- resp, err := client.Do(req)
- c.Check(err, Equals, nil)
- c.Check(resp.StatusCode, Equals, 400)
- body, err := ioutil.ReadAll(resp.Body)
- c.Check(string(body), Matches, ".*Invalid ClusterID.*")
- }
-
- // Registration of an invalid ClusterID (must fail)
- {
- client := http.Client{}
- req, err := http.NewRequest("POST",
- fmt.Sprintf("http://%s/%s", listener.Addr().String(), "v1/register/yabcd"),
- nil)
- resp, err := client.Do(req)
- c.Check(err, Equals, nil)
- c.Check(resp.StatusCode, Equals, 400)
- body, err := ioutil.ReadAll(resp.Body)
- c.Check(string(body), Matches, ".*Invalid ClusterID.*")
- }
-
- // Registration of an invalid ClusterID (must fail)
- {
- client := http.Client{}
- req, err := http.NewRequest("POST",
- fmt.Sprintf("http://%s/%s", listener.Addr().String(), "v1/register/zabcd"),
- nil)
- resp, err := client.Do(req)
- c.Check(err, Equals, nil)
- c.Check(resp.StatusCode, Equals, 400)
- body, err := ioutil.ReadAll(resp.Body)
- c.Check(string(body), Matches, ".*Invalid ClusterID.*")
- }
-
- // Registration of an invalid ClusterID (must fail)
- {
- client := http.Client{}
- req, err := http.NewRequest("POST",
- fmt.Sprintf("http://%s/%s", listener.Addr().String(), "v1/register/ABCDE"),
- nil)
- resp, err := client.Do(req)
- c.Check(err, Equals, nil)
- c.Check(resp.StatusCode, Equals, 400)
- body, err := ioutil.ReadAll(resp.Body)
- c.Check(string(body), Matches, ".*Invalid ClusterID.*")
- }
+ runServer(c)
+ defer closeListener()
+ defer os.Remove(tmpDBFileName)
+ defer os.Remove(tmpConfigFileName)
+
+ // Test the about handler
+ {
+ client := http.Client{}
+ req, err := http.NewRequest("GET",
+ fmt.Sprintf("http://%s/%s", listener.Addr().String(), "v1/about"),
+ nil)
+ resp, err := client.Do(req)
+ c.Check(err, Equals, nil)
+ c.Check(resp.StatusCode, Equals, 200)
+ body, err := ioutil.ReadAll(resp.Body)
+ c.Check(string(body), Matches, ".*\"Name\":\"Arvados Registry Daemon\".*")
+ }
+
+ // Test the help handler
+ {
+ client := http.Client{}
+ req, err := http.NewRequest("GET",
+ fmt.Sprintf("http://%s/%s", listener.Addr().String(), "v1/help"),
+ nil)
+ resp, err := client.Do(req)
+ c.Check(err, Equals, nil)
+ c.Check(resp.StatusCode, Equals, 200)
+ body, err := ioutil.ReadAll(resp.Body)
+ c.Check(string(body), Matches, ".*GET /v1/about or GET /v1/help.*")
+ }
+
+ // Registration of a valid ClusterID with proper JSON body (must pass)
+ {
+ client := http.Client{}
+ var jsonStr = []byte(`{"clientSecret":"this_is_long_enough","name":"Ward Vandewege","email":"sysadmin at curoverse.com","organization":"Curoverse, Inc."}`)
+ req, err := http.NewRequest("POST",
+ fmt.Sprintf("http://%s/%s", listener.Addr().String(), "v1/register/abcde"),
+ bytes.NewBuffer(jsonStr))
+ resp, err := client.Do(req)
+ c.Check(err, Equals, nil)
+ c.Check(resp.StatusCode, Equals, 200)
+ body, err := ioutil.ReadAll(resp.Body)
+ c.Check(string(body), Matches, ".*\"ClusterID\":\"abcde\",\"Available\":false,\"Registered\":true.*")
+ }
+
+ // Check existence of a valid ClusterID (must pass)
+ {
+ client := http.Client{}
+ req, err := http.NewRequest("GET",
+ fmt.Sprintf("http://%s/%s", listener.Addr().String(), "v1/check/abcde"),
+ nil)
+ resp, err := client.Do(req)
+ c.Check(err, Equals, nil)
+ c.Check(resp.StatusCode, Equals, 200)
+ body, err := ioutil.ReadAll(resp.Body)
+ c.Check(string(body), Matches, ".*\"ClusterID\":\"abcde\",\"Available\":false,\"Registered\":true.*")
+ }
+
+ // Check existence of an invalid ClusterID (must pass)
+ {
+ client := http.Client{}
+ req, err := http.NewRequest("GET",
+ fmt.Sprintf("http://%s/%s", listener.Addr().String(), "v1/check/1bcde"),
+ nil)
+ resp, err := client.Do(req)
+ c.Check(err, Equals, nil)
+ c.Check(resp.StatusCode, Equals, 200)
+ body, err := ioutil.ReadAll(resp.Body)
+ c.Check(string(body), Matches, ".*\"ClusterID\":\"1bcde\",\"Available\":false,\"Registered\":false.*")
+ }
+
+ // Registration of a ClusterID with proper JSON body missing fields (must fail)
+ {
+ client := http.Client{}
+ var jsonStr = []byte(`{"clientSecret":"this_is_long_enough"}`)
+ req, err := http.NewRequest("POST",
+ fmt.Sprintf("http://%s/%s", listener.Addr().String(), "v1/register/abcde"),
+ bytes.NewBuffer(jsonStr))
+ resp, err := client.Do(req)
+ c.Check(err, Equals, nil)
+ c.Check(resp.StatusCode, Equals, 400)
+ body, err := ioutil.ReadAll(resp.Body)
+ c.Check(string(body), Matches, ".*Missing fields.*")
+ }
+
+ // Registration of an existing ClusterID with proper JSON body (must fail)
+ {
+ client := http.Client{}
+ var jsonStr = []byte(`{"clientSecret":"this_is_long_enough","name":"Ward Vandewege","email":"sysadmin at curoverse.com","organization":"Curoverse, Inc."}`)
+ req, err := http.NewRequest("POST",
+ fmt.Sprintf("http://%s/%s", listener.Addr().String(), "v1/register/abcde"),
+ bytes.NewBuffer(jsonStr))
+ resp, err := client.Do(req)
+ c.Check(err, Equals, nil)
+ c.Check(resp.StatusCode, Equals, 400)
+ body, err := ioutil.ReadAll(resp.Body)
+ c.Check(string(body), Matches, ".*This ClusterID is not available for registration.*")
+ }
+
+ // Registration of a valid ClusterID with proper JSON body but clientSecret that is too short (must fail)
+ {
+ client := http.Client{}
+ var jsonStr = []byte(`{"clientSecret":"not_long_enough"}`)
+ req, err := http.NewRequest("POST",
+ fmt.Sprintf("http://%s/%s", listener.Addr().String(), "v1/register/abcde"),
+ bytes.NewBuffer(jsonStr))
+ resp, err := client.Do(req)
+ c.Check(err, Equals, nil)
+ c.Check(resp.StatusCode, Equals, 400)
+ body, err := ioutil.ReadAll(resp.Body)
+ c.Check(string(body), Matches, ".*min length: 16 characters.*")
+ }
+
+ // Registration of a valid ClusterID but without JSON body (must fail)
+ {
+ client := http.Client{}
+ req, err := http.NewRequest("POST",
+ fmt.Sprintf("http://%s/%s", listener.Addr().String(), "v1/register/abcde"),
+ nil)
+ resp, err := client.Do(req)
+ c.Check(err, Equals, nil)
+ c.Check(resp.StatusCode, Equals, 400)
+ body, err := ioutil.ReadAll(resp.Body)
+ c.Check(string(body), Matches, ".*Unable to decode request body as JSON.*")
+ }
+
+ // Registration of an invalid ClusterID (must fail)
+ {
+ client := http.Client{}
+ req, err := http.NewRequest("POST",
+ fmt.Sprintf("http://%s/%s", listener.Addr().String(), "v1/register/1abcd"),
+ nil)
+ resp, err := client.Do(req)
+ c.Check(err, Equals, nil)
+ c.Check(resp.StatusCode, Equals, 400)
+ body, err := ioutil.ReadAll(resp.Body)
+ c.Check(string(body), Matches, ".*Invalid ClusterID.*")
+ }
+
+ // Registration of an invalid ClusterID (must fail)
+ {
+ client := http.Client{}
+ req, err := http.NewRequest("POST",
+ fmt.Sprintf("http://%s/%s", listener.Addr().String(), "v1/register/xabcd"),
+ nil)
+ resp, err := client.Do(req)
+ c.Check(err, Equals, nil)
+ c.Check(resp.StatusCode, Equals, 400)
+ body, err := ioutil.ReadAll(resp.Body)
+ c.Check(string(body), Matches, ".*Invalid ClusterID.*")
+ }
+
+ // Registration of an invalid ClusterID (must fail)
+ {
+ client := http.Client{}
+ req, err := http.NewRequest("POST",
+ fmt.Sprintf("http://%s/%s", listener.Addr().String(), "v1/register/yabcd"),
+ nil)
+ resp, err := client.Do(req)
+ c.Check(err, Equals, nil)
+ c.Check(resp.StatusCode, Equals, 400)
+ body, err := ioutil.ReadAll(resp.Body)
+ c.Check(string(body), Matches, ".*Invalid ClusterID.*")
+ }
+
+ // Registration of an invalid ClusterID (must fail)
+ {
+ client := http.Client{}
+ req, err := http.NewRequest("POST",
+ fmt.Sprintf("http://%s/%s", listener.Addr().String(), "v1/register/zabcd"),
+ nil)
+ resp, err := client.Do(req)
+ c.Check(err, Equals, nil)
+ c.Check(resp.StatusCode, Equals, 400)
+ body, err := ioutil.ReadAll(resp.Body)
+ c.Check(string(body), Matches, ".*Invalid ClusterID.*")
+ }
+
+ // Registration of an invalid ClusterID (must fail)
+ {
+ client := http.Client{}
+ req, err := http.NewRequest("POST",
+ fmt.Sprintf("http://%s/%s", listener.Addr().String(), "v1/register/ABCDE"),
+ nil)
+ resp, err := client.Do(req)
+ c.Check(err, Equals, nil)
+ c.Check(resp.StatusCode, Equals, 400)
+ body, err := ioutil.ReadAll(resp.Body)
+ c.Check(string(body), Matches, ".*Invalid ClusterID.*")
+ }
}
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list