diff --git a/.gitignore b/.gitignore index 32fb26f1..9250d7a0 100644 --- a/.gitignore +++ b/.gitignore @@ -61,6 +61,7 @@ crashlytics-build.properties #Other project specific stuff dev1_start.sh +torture_test.sh config.ini frontend/index.html frontend/plugins/plugins.ini diff --git a/common/config/config.go b/common/config/config.go old mode 100644 new mode 100755 index f4d62f49..053f4af3 --- a/common/config/config.go +++ b/common/config/config.go @@ -125,7 +125,7 @@ func LoadDefaults() { Database.UseSSL = false Database.DbAdminUser = "adminuser" Database.DbAdminPassword = "password" - Database.DbTimeout = "500" + Database.DbTimeout = "0" Database.MainDb = "main_ut" Logger.LogFile = "wikifeat-service.log" Logger.MaxSize = 10 diff --git a/config/config_loader/config_loader_test.go b/config/config_loader/config_loader_test.go old mode 100644 new mode 100755 index 5e020f65..b88ac19f --- a/config/config_loader/config_loader_test.go +++ b/config/config_loader/config_loader_test.go @@ -54,8 +54,6 @@ func TestConfigLoader(t *testing.T) { config_loader.SetConfig() //Reset the local config to defaults config.LoadDefaults() - //Load config from etcd - config.FetchConfig() //Check the config items we set if config.Notifications.FromEmail != "turd.furgeson@nowhere.com" { t.Errorf("Notifications.FromEmail not set: %v", config.Notifications.FromEmail) diff --git a/users/user_service/users_test.go b/users/user_service/users_test.go old mode 100644 new mode 100755 index a94c6af8..be784a21 --- a/users/user_service/users_test.go +++ b/users/user_service/users_test.go @@ -32,7 +32,6 @@ package user_service_test import ( "fmt" "github.com/rhinoman/wikifeat/Godeps/_workspace/src/github.com/rhinoman/couchdb-go" - . "github.com/rhinoman/wikifeat/Godeps/_workspace/src/github.com/smartystreets/goconvey/convey" "github.com/rhinoman/wikifeat/Godeps/_workspace/src/github.com/twinj/uuid" "github.com/rhinoman/wikifeat/common/config" "github.com/rhinoman/wikifeat/common/database" @@ -101,201 +100,214 @@ func TestUsers(t *testing.T) { } um.Delete("Steven.Smith", getSmithUser()) }() - Convey("Given a new account registration", t, func() { - user := entities.User{ - UserName: "Steven.Smith", - Password: "jabberwocky", - Public: entities.UserPublic{ - LastName: "Smith", - FirstName: "Steven", - }, - } - registration := user_service.Registration{ - NewUser: user, - } - Convey("When the new user is registered", func() { - rev, err := um.SetUp(®istration) - Convey("The revision should be set and the error should be nil", func() { - So(err, ShouldBeNil) - So(rev, ShouldNotEqual, "") - t.Logf("New user revision: %v", rev) - }) - }) - Convey("When a new user for the account is created", func() { - subUser := entities.User{ - UserName: "Sally.Smith", - Password: "123456", - Public: entities.UserPublic{ - LastName: "Smith", - FirstName: "Sally", - }, - } - rev, err := um.Create(&subUser, smithUser()) - Convey("The revision should be set and the error should be nil", func() { - So(err, ShouldBeNil) - So(rev, ShouldNotEqual, "") - }) - Convey("The user should have the appropriate roles", func() { - So(util.HasRole(subUser.Roles, "all_users"), ShouldEqual, true) - }) - }) - Convey("When the user is updated", func() { - auth := couchdb.BasicAuth{Username: "Sally.Smith", Password: "123456"} - updateUser := entities.User{} - rev, err := um.Read("Sally.Smith", &updateUser, smithUser()) - So(err, ShouldBeNil) - curUser := entities.CurrentUserInfo{ - User: &updateUser, - Auth: &auth, - } - - updateUser.Public.MiddleName = "Marie" - rev, err = um.Update("Sally.Smith", rev, &updateUser, &curUser) - Convey("Error should be nil and the revision should be set", func() { - So(err, ShouldBeNil) - So(rev, ShouldNotEqual, "") - }) - rev, err = um.Read("Sally.Smith", &updateUser, smithUser()) - Convey("The user's password should still be valid", func() { - So(err, ShouldBeNil) - So(rev, ShouldNotEqual, "") - }) - - }) - Convey("When the user's password is changed", func() { - auth := couchdb.BasicAuth{Username: "Sally.Smith", Password: "123456"} - updateUser := entities.User{} - rev, err := um.Read("Sally.Smith", &updateUser, smithUser()) - So(err, ShouldBeNil) - curUser := entities.CurrentUserInfo{ - User: &updateUser, - Auth: &auth, - } - newPassword := "234567" - cpr := user_service.ChangePasswordRequest{ - NewPassword: newPassword, - OldPassword: "123456", - } - rev, err = um.ChangePassword("Sally.Smith", rev, &cpr, &curUser) - Convey("Error should be nil and the revision should be set", func() { - So(err, ShouldBeNil) - So(rev, ShouldNotEqual, "") - }) - rev, err = um.Read("Sally.Smith", &updateUser, &curUser) - Convey("Old password should NOT work", func() { - So(err, ShouldNotBeNil) - }) - curUser.Auth = &couchdb.BasicAuth{Username: "Sally.Smith", Password: "234567"} - rev, err = um.Read("Sally.Smith", &updateUser, &curUser) - Convey("New password should work", func() { - So(err, ShouldBeNil) - So(rev, ShouldNotEqual, "") - }) - - }) - Convey("When a user is granted a role", func() { - curUser := smithUser() - roleRequest := user_service.RoleRequest{ - ResourceType: "main", - ResourceId: "", - AccessType: "write", - } - rev, err := um.GrantRole("Sally.Smith", &roleRequest, curUser) - Convey("The revision should be set and the error should be nil", func() { - So(err, ShouldBeNil) - So(rev, ShouldNotEqual, "") - }) - Convey("User should have her new role", func() { - readUser := new(entities.User) - _, err := um.Read("Sally.Smith", readUser, smithUser()) - So(err, ShouldBeNil) - t.Logf("Sally's Record: %v", readUser) - searchRole := "main_" + ":write" - searchRoleFound := false - if readUser.Roles[2] == searchRole { - searchRoleFound = true - } - So(searchRoleFound, ShouldEqual, true) - }) - - }) - Convey("When a user has a role revoked", func() { - curUser := smithUser() - roleRequest := user_service.RoleRequest{ - ResourceType: "main", - ResourceId: "", - AccessType: "write", - } - rev, err := um.RevokeRole("Sally.Smith", &roleRequest, curUser) - Convey("The revision should be set and the error should be nil", func() { - So(err, ShouldBeNil) - So(rev, ShouldNotEqual, "") - }) - Convey("User should no longer have her role", func() { - readUser := new(entities.User) - _, err := um.Read("Sally.Smith", readUser, smithUser()) - So(err, ShouldBeNil) - searchRole := "main" + ":write" - searchRoleFound := false - if len(readUser.Roles) > 1 && readUser.Roles[1] == searchRole { - searchRoleFound = true - } - So(searchRoleFound, ShouldEqual, false) + //Create a new master user + user := entities.User{ + UserName: "Steven.Smith", + Password: "jabberwocky", + Public: entities.UserPublic{ + LastName: "Smith", + FirstName: "Steven", + }, + } + registration := user_service.Registration{ + NewUser: user, + } + rev, err := um.SetUp(®istration) + if err != nil { + t.Error(err) + } + if rev == "" { + t.Error("rev is empty!") + } + t.Logf("New user revision: %v", rev) + //Create a new subuser + subUser := entities.User{ + UserName: "Sally.Smith", + Password: "123456", + Public: entities.UserPublic{ + LastName: "Smith", + FirstName: "Sally", + }, + } + rev, err = um.Create(&subUser, smithUser()) + if err != nil { + t.Error(err) + } + if rev == "" { + t.Error("rev is empty!") + } + if !util.HasRole(subUser.Roles, "all_users"){ + t.Error("user doesn't have all_users role!") + } + //Update user + auth := couchdb.BasicAuth{Username: "Sally.Smith", Password: "123456"} + updateUser := entities.User{} + rev, err = um.Read("Sally.Smith", &updateUser, smithUser()) + if err != nil { + t.Error(err) + } + curUser := entities.CurrentUserInfo{ + User: &updateUser, + Auth: &auth, + } - }) - }) - Convey("When the user list is requested", func() { - userList := user_service.UserListQueryResponse{} - err := um.GetUserList(1, 5, &userList, smithUser()) - Convey("Error should be nil and we should have some results", func() { - So(err, ShouldBeNil) - So(len(userList.Rows) >= 2, ShouldBeTrue) - t.Logf("UserListResponse: %v", userList) - }) - }) - Convey("When a user search is requested", func() { - userList := user_service.UserListQueryResponse{} - err := um.SearchForUsersByName(1, 5, "Smith", &userList, smithUser()) - Convey("Error should be nil and we should have some results", func() { - So(err, ShouldBeNil) - So(len(userList.Rows), ShouldEqual, 2) - t.Logf("UserListResponse: %v", userList) - }) - }) - Convey("When the user is read", func() { - readUser := entities.User{} - rev, err := um.Read(user.UserName, &readUser, smithUser()) - Convey("The revision should be set and the error should be nil", func() { - So(err, ShouldBeNil) - So(rev, ShouldNotEqual, "") - }) - Convey("The user data should be set", func() { - So(readUser.CreatedAt, ShouldNotBeNil) - So(readUser.UserName, ShouldEqual, "Steven.Smith") - }) - }) - Convey("When the user by roles list is requested", func() { - userList := user_service.UserListQueryResponse{} - err := um.GetUserListForRole(1, 5, []string{"all_users"}, - &userList, smithUser()) - Convey("The error should be nil and we should have some results", func() { - So(err, ShouldBeNil) - t.Logf("Response: %v", userList) - }) - }) - Convey("When a user password reset is requested", func() { - err := um.RequestPasswordReset("Steven.Smith") - Convey("The error should indicate no notifcation services are present", func() { - So(err.Error(), ShouldEqual, "No notifications services listed!") - }) - }) - Convey("When the user is deleted", func() { - rev, err := um.Delete("Sally.Smith", smithUser()) - Convey("The revision should be set and the error should be nil", func() { - So(err, ShouldBeNil) - So(rev, ShouldNotEqual, "") - t.Logf("Deleted User rev: %v", rev) - }) - }) - }) + updateUser.Public.MiddleName = "Marie" + rev, err = um.Update("Sally.Smith", rev, &updateUser, &curUser) + if err != nil { + t.Error(err) + } + if rev == "" { + t.Error("rev is empty!") + } + rev, err = um.Read("Sally.Smith", &updateUser, smithUser()) + if err != nil { + t.Error(err) + } + if rev == "" { + t.Error("rev is empty!") + } + //Change password + auth = couchdb.BasicAuth{Username: "Sally.Smith", Password: "123456"} + updateUser = entities.User{} + rev, err = um.Read("Sally.Smith", &updateUser, smithUser()) + if err != nil { + t.Error(err) + } + curUser = entities.CurrentUserInfo{ + User: &updateUser, + Auth: &auth, + } + newPassword := "234567" + cpr := user_service.ChangePasswordRequest{ + NewPassword: newPassword, + OldPassword: "123456", + } + rev, err = um.ChangePassword("Sally.Smith", rev, &cpr, &curUser) + if err != nil { + t.Error(err) + } + if rev == "" { + t.Error("rev is empty!") + } + rev, err = um.Read("Sally.Smith", &updateUser, &curUser) + if err == nil { + t.Error("Old password should not have worked!") + } + curUser.Auth = &couchdb.BasicAuth{Username: "Sally.Smith", Password: "234567"} + rev, err = um.Read("Sally.Smith", &updateUser, &curUser) + if err != nil { + t.Error(err) + } + if rev == "" { + t.Error("rev is empty!") + } + //Grant role + curUser = *smithUser() + roleRequest := user_service.RoleRequest{ + ResourceType: "main", + ResourceId: "", + AccessType: "write", + } + rev, err = um.GrantRole("Sally.Smith", &roleRequest, &curUser) + if err != nil { + t.Error(err) + } + if rev == "" { + t.Error("rev is empty!") + } + readUser := new(entities.User) + _, err = um.Read("Sally.Smith", readUser, smithUser()) + if err != nil { + t.Error(err) + } + t.Logf("Sally's Record: %v", readUser) + searchRole := "main_" + ":write" + searchRoleFound := false + if readUser.Roles[2] == searchRole { + searchRoleFound = true + } + if !searchRoleFound{ + t.Error("Role not found!") + } + //Revoke role + curUser = *smithUser() + roleRequest = user_service.RoleRequest{ + ResourceType: "main", + ResourceId: "", + AccessType: "write", + } + rev, err = um.RevokeRole("Sally.Smith", &roleRequest, &curUser) + if err != nil { + t.Error(err) + } + if rev == "" { + t.Error("rev is empty!") + } + readUser = new(entities.User) + _, err = um.Read("Sally.Smith", readUser, smithUser()) + if err != nil { + t.Error(err) + } + searchRole = "main" + ":write" + searchRoleFound = false + if len(readUser.Roles) > 1 && readUser.Roles[1] == searchRole { + searchRoleFound = true + } + if searchRoleFound { + t.Error("Role should not have been found!") + } + //User List + userList := user_service.UserListQueryResponse{} + err = um.GetUserList(1, 5, &userList, smithUser()) + if err != nil { + t.Error(err) + } + if !(len(userList.Rows) >= 2){ + t.Error("User list should be greater than or equal to 2!") + } + t.Logf("UserListResponse: %v", userList) + //User search + userList = user_service.UserListQueryResponse{} + err = um.SearchForUsersByName(1, 5, "Smith", &userList, smithUser()) + if err != nil { + t.Error(err) + } + if len(userList.Rows) != 2{ + t.Errorf("Userlist should be length 2 was %v", len(userList.Rows)) + } + t.Logf("UserListResponse: %v", userList) + //Read user + readUser = &entities.User{} + rev, err = um.Read(user.UserName, readUser, smithUser()) + if err != nil { + t.Error(err) + } + if rev == "" { + t.Error("Rev is empty!") + } + if readUser.UserName != "Steven.Smith"{ + t.Errorf("username should be Seteven.Smith, was %v", readUser.UserName) + } + //User by Roles list + userList = user_service.UserListQueryResponse{} + err = um.GetUserListForRole(1, 5, []string{"all_users"}, + &userList, smithUser()) + if err != nil { + t.Error(err) + } + t.Logf("Response: %v", userList) + //Password reset + err = um.RequestPasswordReset("Steven.Smith") + if err.Error() != "No notifications services listed!"{ + t.Error("Error is wrong") + } + //Delete user + rev, err = um.Delete("Sally.Smith", smithUser()) + if err != nil { + t.Error(err) + } + if rev == "" { + t.Error("Rev is empty!") + } + t.Logf("Deleted User rev: %v", rev) } diff --git a/wikis/wiki_service/file_test.go b/wikis/wiki_service/file_test.go old mode 100644 new mode 100755 index 24a93f28..f97c2cad --- a/wikis/wiki_service/file_test.go +++ b/wikis/wiki_service/file_test.go @@ -32,18 +32,19 @@ package wiki_service_test import ( "bytes" - "github.com/rhinoman/wikifeat/Godeps/_workspace/src/github.com/rhinoman/couchdb-go" . "github.com/rhinoman/wikifeat/common/entities" "github.com/rhinoman/wikifeat/users/user_service" "github.com/rhinoman/wikifeat/wikis/wiki_service/wikit" "io/ioutil" "testing" + "time" ) func beforeFileTest(t *testing.T) error { - setup() + time.Sleep(200 * time.Millisecond) + setup("main_files_test") user := User{ - UserName: "John.Smith", + UserName: "Jim.Smith", Password: "password", } registration := user_service.Registration{ @@ -56,29 +57,14 @@ func beforeFileTest(t *testing.T) error { return nil } -func TestFileCRUD(t *testing.T) { - err := beforeFileTest(t) - jsAuth := &couchdb.BasicAuth{ - Username: "John.Smith", - Password: "password", - } - if err != nil { - t.Error(err) - } - theUser := User{} - _, err = grabUser("John.Smith", &theUser, jsAuth) - if err != nil { - t.Error(err) - } - defer afterTest(&theUser) +func doFileTest(t *testing.T) { //Create a wiki - curUser := getCurUser(jsAuth) wikiId := getUuid() wikiRecord := WikiRecord{ Name: "Cafe Project", Description: "Wiki for the Cafe Project", } - _, err = wm.Create(wikiId, &wikiRecord, curUser) + _, err := wm.Create(wikiId, &wikiRecord, curUser) if err != nil { t.Error(err) } diff --git a/wikis/wiki_service/pages_test.go b/wikis/wiki_service/pages_test.go old mode 100644 new mode 100755 index 4190ef31..06f4accf --- a/wikis/wiki_service/pages_test.go +++ b/wikis/wiki_service/pages_test.go @@ -32,48 +32,17 @@ package wiki_service_test import ( "encoding/json" - "github.com/rhinoman/wikifeat/Godeps/_workspace/src/github.com/rhinoman/couchdb-go" - . "github.com/rhinoman/wikifeat/Godeps/_workspace/src/github.com/smartystreets/goconvey/convey" . "github.com/rhinoman/wikifeat/common/entities" - "github.com/rhinoman/wikifeat/users/user_service" "github.com/rhinoman/wikifeat/wikis/wiki_service/wikit" "testing" ) -func beforePageTest(t *testing.T) error { - setup() - user := User{ - UserName: "John.Smith", - Password: "password", - } - registration := user_service.Registration{ - NewUser: user, - } - _, err := um.SetUp(®istration) - if err != nil { - return err - } - return nil +func cleanup(wikiId string){ + wm.Delete(wikiId, curUser) } -func TestPageCRUD(t *testing.T) { - err := beforePageTest(t) - jsAuth := &couchdb.BasicAuth{ - Username: "John.Smith", - Password: "password", - } - if err != nil { - t.Error(err) - t.Fail() - } - theUser := User{} - _, err = grabUser("John.Smith", &theUser, jsAuth) - if err != nil { - t.Error(err) - } - defer afterTest(&theUser) +func doPageTest(t *testing.T) { //Create a wiki - curUser := getCurUser(jsAuth) wikiId := getUuid() pageId := getUuid() sPageId := getUuid() @@ -85,206 +54,209 @@ func TestPageCRUD(t *testing.T) { Name: "Cafe Project", Description: "Wiki for the Cafe Project", } - _, err = wm.Create(wikiId, &wikiRecord, curUser) + _, err := wm.Create(wikiId, &wikiRecord, curUser) if err != nil { t.Error(err) } - defer wm.Delete(wikiId, curUser) - Convey("Given a Page with some basic content", t, func() { - //Create a page with some markdown - content := wikit.PageContent{ - Raw: "About\n=\nAbout the project\n--\n", - Formatted: "", - } - page := wikit.Page{ - Content: content, - Title: "About", - } - //page = jsonifyPage(page) - //Create another page - sContent := wikit.PageContent{ - Raw: "Contact\n=\nContact Us\n--\n", - Formatted: "", - } - sPage := wikit.Page{ - Content: sContent, - Title: "Contact Us", - Parent: pageId, - } - //sPage = jsonifyPage(sPage) - - Convey("When the pages are saved", func() { - rev, err := pm.Save(wikiId, &page, pageId, "", curUser) - sRev, sErr := pm.Save(wikiId, &sPage, sPageId, "", curUser) - pageSlug = page.Slug - Convey("The revision should be set and the error should be nil", func() { - So(rev, ShouldNotEqual, "") - So(err, ShouldBeNil) - So(sRev, ShouldNotEqual, "") - So(sErr, ShouldBeNil) - }) - }) - Convey("When the Page is Read", func() { - rPage := wikit.Page{} - wikiId, rev, err := pm.ReadBySlug(wikiRecord.Slug, pageSlug, &rPage, curUser) - Convey("The revision should be set and the error should be nil", func() { - So(wikiId, ShouldNotBeNil) - So(rev, ShouldNotEqual, "") - So(err, ShouldBeNil) - }) - Convey("The Html content should be correct", func() { - content = rPage.Content - So(content.Formatted, ShouldEqual, - "