From feb57f7677946f9dd20acbdf432ec5738a2239d9 Mon Sep 17 00:00:00 2001 From: Piotr Zduniak Date: Thu, 15 Jan 2015 23:34:57 +0100 Subject: [PATCH 1/7] Added email to docker login in the CD script --- circle.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/circle.yml b/circle.yml index e279473..60f9f5a 100644 --- a/circle.yml +++ b/circle.yml @@ -31,6 +31,6 @@ deployment: hub: branch: master commands: - - docker login -u $DOCKER_USER -p $DOCKER_PASS https://registry.lavaboom.io + - docker login -e circleci@lavaboom.io -u $DOCKER_USER -p $DOCKER_PASS https://registry.lavaboom.io - docker build -t registry.lavaboom.io/api/master - docker push registry.lavaboom.io/api/master \ No newline at end of file From 30193a2410e9d210219eedef8ebe46fb95fcf0a3 Mon Sep 17 00:00:00 2001 From: Piotr Zduniak Date: Thu, 15 Jan 2015 23:38:14 +0100 Subject: [PATCH 2/7] solved the case of a disappearing dot --- circle.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/circle.yml b/circle.yml index 60f9f5a..d9b0ecb 100644 --- a/circle.yml +++ b/circle.yml @@ -32,5 +32,5 @@ deployment: branch: master commands: - docker login -e circleci@lavaboom.io -u $DOCKER_USER -p $DOCKER_PASS https://registry.lavaboom.io - - docker build -t registry.lavaboom.io/api/master + - docker build -t registry.lavaboom.io/api/master . - docker push registry.lavaboom.io/api/master \ No newline at end of file From 390a818c2ed02c5055eca85bb4696d09756a9701 Mon Sep 17 00:00:00 2001 From: Piotr Zduniak Date: Thu, 15 Jan 2015 23:42:12 +0100 Subject: [PATCH 3/7] Docker namespace can't match any original routes --- circle.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/circle.yml b/circle.yml index d9b0ecb..74499a0 100644 --- a/circle.yml +++ b/circle.yml @@ -32,5 +32,5 @@ deployment: branch: master commands: - docker login -e circleci@lavaboom.io -u $DOCKER_USER -p $DOCKER_PASS https://registry.lavaboom.io - - docker build -t registry.lavaboom.io/api/master . - - docker push registry.lavaboom.io/api/master \ No newline at end of file + - docker build -t registry.lavaboom.io/lavaboom/api . + - docker push registry.lavaboom.io/lavaboom/api \ No newline at end of file From 0917a79336a60f555cde4d49ca75690c8b6a48af Mon Sep 17 00:00:00 2001 From: Piotr Zduniak Date: Fri, 16 Jan 2015 12:21:52 +0100 Subject: [PATCH 4/7] Weak password wasn't weak enough --- routes/accounts_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routes/accounts_test.go b/routes/accounts_test.go index 4d70454..e452b48 100644 --- a/routes/accounts_test.go +++ b/routes/accounts_test.go @@ -281,7 +281,7 @@ func TestAccountsRoute(t *testing.T) { Body: routes.AccountsCreateRequest{ Username: account.Name, InviteCode: verificationToken.ID, - Password: "c0067d4af4e87f00dbac63b6156828237059172d1bbeac67427345d6a9fda484", + Password: "d0cfc2e5319b82cdc71a33873e826c93d7ee11363f8ac91c4fa3a2cfcd2286e5", }, }.Do() From 074dd3a57374634ae8c056bb2c77bedf0251b9db Mon Sep 17 00:00:00 2001 From: Piotr Zduniak Date: Fri, 16 Jan 2015 14:24:25 +0100 Subject: [PATCH 5/7] From field in newly created emails --- env/config.go | 1 + main.go | 2 ++ routes/emails.go | 17 +++++++++++++++++ 3 files changed, 20 insertions(+) diff --git a/env/config.go b/env/config.go index ce13ae1..474ef19 100644 --- a/env/config.go +++ b/env/config.go @@ -6,6 +6,7 @@ type Flags struct { APIVersion string LogFormatterType string ForceColors bool + EmailDomain string SessionDuration int ClassicRegistration bool diff --git a/main.go b/main.go index e188a0c..3859208 100644 --- a/main.go +++ b/main.go @@ -25,6 +25,7 @@ var ( apiVersion = flag.String("api_version", "v0", "Shown API version") logFormatterType = flag.String("log", "text", "Log formatter type. Either \"json\" or \"text\"") forceColors = flag.Bool("force_colors", false, "Force colored prompt?") + emailDomain = flag.String("email_domain", "lavaboom.io", "Domain of the default email service") // Registration settings sessionDuration = flag.Int("session_duration", 72, "Session duration expressed in hours") classicRegistration = flag.Bool("classic_registration", false, "Classic registration enabled?") @@ -86,6 +87,7 @@ func main() { APIVersion: *apiVersion, LogFormatterType: *logFormatterType, ForceColors: *forceColors, + EmailDomain: *emailDomain, SessionDuration: *sessionDuration, ClassicRegistration: *classicRegistration, diff --git a/routes/emails.go b/routes/emails.go index 1c6d2fe..5144ee7 100644 --- a/routes/emails.go +++ b/routes/emails.go @@ -174,9 +174,26 @@ func EmailsCreate(c web.C, w http.ResponseWriter, r *http.Request) { return } + // Fetch the user object from the database + account, err := env.Accounts.GetTokenOwner(c.Env["token"].(*models.Token)) + if err != nil { + // The session refers to a non-existing user + env.Log.WithFields(logrus.Fields{ + "id": session.ID, + "error": err.Error(), + }).Warn("Valid session referred to a removed account") + + utils.JSONResponse(w, 410, &EmailsCreateResponse{ + Success: false, + Message: "Account disabled", + }) + return + } + // Create a new email struct email := &models.Email{ Kind: "sent", + From: []string{account.Name + "@" + env.Config.EmailDomain}, To: input.To, Resource: models.MakeResource(session.Owner, input.Subject), AttachmentIDs: input.Attachments, From 3d031bde36858bb521fa107a1a77a763349755a1 Mon Sep 17 00:00:00 2001 From: Piotr Zduniak Date: Fri, 16 Jan 2015 21:18:03 +0100 Subject: [PATCH 6/7] Added a coveralls endpoint to .circle.yml --- circle.yml | 5 ++++- routes/accounts_test.go | 40 ++++++++++++++++++++-------------------- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/circle.yml b/circle.yml index 74499a0..a99153b 100644 --- a/circle.yml +++ b/circle.yml @@ -15,6 +15,8 @@ dependencies: - if [[ ! -e redis-2.8.18/src/redis-server ]]; then wget http://download.redis.io/releases/redis-2.8.18.tar.gz && tar xvzf redis-2.8.18.tar.gz; fi - if [[ ! -e redis-2.8.18/src/redis-server ]]; then cd redis-2.8.18 && make; fi - go get github.com/apcera/gnatsd + - go get golang.org/x/tools/cmd/cover + - go get github.com/mattn/goveralls post: - rethinkdb --bind all: background: true @@ -25,7 +27,8 @@ dependencies: test: override: - - go test -v ./... + - go test -v -covermode=count -coverprofile=coverage.out ./... + - goveralls -coverprofile=coverage.out -service=circleci -repotoken $COVERALLS_TOKEN deployment: hub: diff --git a/routes/accounts_test.go b/routes/accounts_test.go index e452b48..afff395 100644 --- a/routes/accounts_test.go +++ b/routes/accounts_test.go @@ -61,10 +61,10 @@ func TestAccountsRoute(t *testing.T) { Method: "POST", Uri: server.URL + "/accounts", ContentType: "application/json", - Body: routes.AccountsCreateRequest{ - Username: username, - AltEmail: email, - }, + Body: `{ + "username": "` + username + `", + "alt_email": "` + email + `" +}`, }.Do() So(err, ShouldBeNil) @@ -83,10 +83,10 @@ func TestAccountsRoute(t *testing.T) { Method: "POST", Uri: server.URL + "/accounts", ContentType: "application/json", - Body: routes.AccountsCreateRequest{ - Username: username, - AltEmail: email, - }, + Body: `{ + "username": "` + username + `", + "alt_email": "` + email + `" + }`, }.Do() So(err, ShouldBeNil) @@ -103,10 +103,10 @@ func TestAccountsRoute(t *testing.T) { Method: "POST", Uri: server.URL + "/accounts", ContentType: "application/json", - Body: routes.AccountsCreateRequest{ - Username: uniuri.New(), - AltEmail: email, - }, + Body: `{ + "username": "` + uniuri.New() + `", + "alt_email": "` + email + `" + }`, }.Do() So(err, ShouldBeNil) @@ -123,10 +123,10 @@ func TestAccountsRoute(t *testing.T) { Method: "POST", Uri: server.URL + "/accounts", ContentType: "application/json", - Body: routes.AccountsCreateRequest{ - Username: uniuri.New(), - InviteCode: uniuri.New(), - }, + Body: `{ + "username": "` + uniuri.New() + `", + "invite_code": "` + uniuri.New() + `" + }`, }.Do() So(err, ShouldBeNil) @@ -143,10 +143,10 @@ func TestAccountsRoute(t *testing.T) { Method: "POST", Uri: server.URL + "/accounts", ContentType: "application/json", - Body: routes.AccountsCreateRequest{ - Username: account.Name, - InviteCode: uniuri.New(), - }, + Body: `{ + "username": "` + account.Name + `", + "invite_code": "` + uniuri.New() + `" + }`, }.Do() So(err, ShouldBeNil) From e48951f288152f5bd0620c35543f59df3a9e82fc Mon Sep 17 00:00:00 2001 From: Piotr Zduniak Date: Fri, 16 Jan 2015 21:20:32 +0100 Subject: [PATCH 7/7] Fixed paths in circle.yml --- circle.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/circle.yml b/circle.yml index a99153b..acf9014 100644 --- a/circle.yml +++ b/circle.yml @@ -27,7 +27,8 @@ dependencies: test: override: - - go test -v -covermode=count -coverprofile=coverage.out ./... + - go test -v github.com/lavab/api/setup + - go test -v -covermode=count -coverprofile=coverage.out github.com/lavab/api/routes - goveralls -coverprofile=coverage.out -service=circleci -repotoken $COVERALLS_TOKEN deployment: