-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[upd][#44] refactored auth and db mocks. Everything compiles but 3 st…
…orageservice tests are failing. (TestStorageResourceFlow, TestStorageUploadResourceDuplicated, TestStorageDeleteJobDuplicated)
- Loading branch information
Federico Maggi
committed
Sep 6, 2016
1 parent
5d33320
commit cd06e93
Showing
10 changed files
with
203 additions
and
409 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,9 +23,9 @@ import ( | |
|
||
// Internal dependencies. | ||
import ( | ||
ty "github.com/nexocrew/3nigm4/lib/auth/types" | ||
db "github.com/nexocrew/3nigm4/lib/database/client" | ||
aty "github.com/nexocrew/3nigm4/lib/auth/types" | ||
"github.com/nexocrew/3nigm4/lib/database/mock" | ||
dty "github.com/nexocrew/3nigm4/lib/database/types" | ||
"github.com/nexocrew/3nigm4/lib/itm" | ||
"github.com/nexocrew/3nigm4/lib/logger" | ||
wq "github.com/nexocrew/3nigm4/lib/workingqueue" | ||
|
@@ -34,8 +34,8 @@ import ( | |
// Default bcrypt iterations | ||
const kBCryptIterations = 10 | ||
|
||
func mockStartup(arguments *args) (db.Database, error) { | ||
mockdb := dbmock.NewMockDb(&db.DbArgs{ | ||
func mockStartup(arguments *args) (dty.Database, error) { | ||
mockdb := dbmock.NewMockDb(&dty.DbArgs{ | ||
Addresses: strings.Split(arguments.dbAddresses, ","), | ||
User: arguments.dbUsername, | ||
Password: arguments.dbPassword, | ||
|
@@ -59,16 +59,16 @@ func prepareMockDb(db *dbmock.Mockdb) error { | |
if err != nil { | ||
return err | ||
} | ||
err = db.SetUser(&ty.User{ | ||
err = db.SetUser(&aty.User{ | ||
Username: "userA", | ||
FullName: "user A", | ||
Email: "[email protected]", | ||
IsDisabled: false, | ||
HashedPassword: hash, | ||
Permissions: ty.Permissions{ | ||
Permissions: aty.Permissions{ | ||
SuperAdmin: false, | ||
Services: map[string]ty.Level{ | ||
"test": ty.LevelAdmin, | ||
Services: map[string]aty.Level{ | ||
"test": aty.LevelAdmin, | ||
}, | ||
}, | ||
}) | ||
|
@@ -81,13 +81,13 @@ func prepareMockDb(db *dbmock.Mockdb) error { | |
if err != nil { | ||
return err | ||
} | ||
err = db.SetUser(&ty.User{ | ||
err = db.SetUser(&aty.User{ | ||
Username: "asuperadmin", | ||
FullName: "Super Admin", | ||
Email: "[email protected]", | ||
IsDisabled: false, | ||
HashedPassword: hash, | ||
Permissions: ty.Permissions{ | ||
Permissions: aty.Permissions{ | ||
SuperAdmin: true, | ||
}, | ||
}) | ||
|
@@ -185,8 +185,8 @@ func TestRPCServe(t *testing.T) { | |
t.Logf("Client connected to %s.\n", address) | ||
|
||
// login | ||
var loginResponse ty.LoginResponseArg | ||
err = client.Call("Login.Login", &ty.LoginRequestArg{ | ||
var loginResponse aty.LoginResponseArg | ||
err = client.Call("Login.Login", &aty.LoginRequestArg{ | ||
Username: "userA", | ||
Password: "passwordA", | ||
}, &loginResponse) | ||
|
@@ -200,8 +200,8 @@ func TestRPCServe(t *testing.T) { | |
t.Fatalf("Invalid token size, having %d expecting 64.\n", len(loginResponse.Token)) | ||
} | ||
// session validation | ||
var sessionResponse ty.AuthenticateResponseArg | ||
err = client.Call("SessionAuth.Authenticate", &ty.AuthenticateRequestArg{ | ||
var sessionResponse aty.AuthenticateResponseArg | ||
err = client.Call("SessionAuth.Authenticate", &aty.AuthenticateRequestArg{ | ||
Token: loginResponse.Token, | ||
}, &sessionResponse) | ||
if err != nil { | ||
|
@@ -211,19 +211,19 @@ func TestRPCServe(t *testing.T) { | |
t.Fatalf("Wrong username, having %s expecting \"userA\".\n", sessionResponse.Username) | ||
} | ||
// userinfo | ||
var userinfoResponse ty.UserInfoResponseArg | ||
err = client.Call("SessionAuth.UserInfo", &ty.AuthenticateRequestArg{ | ||
var userinfoResponse aty.UserInfoResponseArg | ||
err = client.Call("SessionAuth.UserInfo", &aty.AuthenticateRequestArg{ | ||
Token: loginResponse.Token, | ||
}, &userinfoResponse) | ||
if err != nil { | ||
t.Fatalf("Unable to get userinfo: %s.\n", err.Error()) | ||
} | ||
if userinfoResponse.Permissions.Services["test"] != ty.LevelAdmin { | ||
t.Fatalf("Wrong auth level, having %d expecting %d.\n", userinfoResponse.Permissions.Services["test"], ty.LevelAdmin) | ||
if userinfoResponse.Permissions.Services["test"] != aty.LevelAdmin { | ||
t.Fatalf("Wrong auth level, having %d expecting %d.\n", userinfoResponse.Permissions.Services["test"], aty.LevelAdmin) | ||
} | ||
// logout | ||
var logoutResponse ty.LogoutResponseArg | ||
err = client.Call("Login.Logout", &ty.LogoutRequestArg{ | ||
var logoutResponse aty.LogoutResponseArg | ||
err = client.Call("Login.Logout", &aty.LogoutRequestArg{ | ||
Token: loginResponse.Token, | ||
}, &logoutResponse) | ||
if err != nil { | ||
|
@@ -245,8 +245,8 @@ func TestRPCServeSuperAdmin(t *testing.T) { | |
t.Logf("Client connected to %s.\n", address) | ||
|
||
// login | ||
var loginResponse ty.LoginResponseArg | ||
err = client.Call("Login.Login", &ty.LoginRequestArg{ | ||
var loginResponse aty.LoginResponseArg | ||
err = client.Call("Login.Login", &aty.LoginRequestArg{ | ||
Username: "asuperadmin", | ||
Password: "passwordS", | ||
}, &loginResponse) | ||
|
@@ -260,23 +260,23 @@ func TestRPCServeSuperAdmin(t *testing.T) { | |
t.Fatalf("Invalid token size, having %d expecting 64.\n", len(loginResponse.Token)) | ||
} | ||
// create user | ||
var voidResponse ty.VoidResponseArg | ||
var voidResponse aty.VoidResponseArg | ||
hash, err := bcryptPassword("passwordB") | ||
if err != nil { | ||
t.Fatalf("Unable to bcrypt password: %s.\n", err.Error()) | ||
} | ||
err = client.Call("SessionAuth.UpsertUser", &ty.UpserUserRequestArg{ | ||
err = client.Call("SessionAuth.UpsertUser", &aty.UpserUserRequestArg{ | ||
Token: loginResponse.Token, | ||
User: ty.User{ | ||
User: aty.User{ | ||
Username: "userB", | ||
FullName: "user B", | ||
Email: "[email protected]", | ||
IsDisabled: false, | ||
HashedPassword: hash, | ||
Permissions: ty.Permissions{ | ||
Permissions: aty.Permissions{ | ||
SuperAdmin: false, | ||
Services: map[string]ty.Level{ | ||
"test": ty.LevelAdmin, | ||
Services: map[string]aty.Level{ | ||
"test": aty.LevelAdmin, | ||
}, | ||
}, | ||
}, | ||
|
@@ -285,24 +285,24 @@ func TestRPCServeSuperAdmin(t *testing.T) { | |
t.Fatalf("Unable to upsert user: %S.\n", err.Error()) | ||
} | ||
// remove user | ||
err = client.Call("SessionAuth.RemoveUser", &ty.RemoveUserRequestArg{ | ||
err = client.Call("SessionAuth.RemoveUser", &aty.RemoveUserRequestArg{ | ||
Token: loginResponse.Token, | ||
Username: "userB", | ||
}, &voidResponse) | ||
if err != nil { | ||
t.Fatalf("Unable to remove user: %s.\n", err.Error()) | ||
} | ||
// kick off all sessions | ||
err = client.Call("SessionAuth.KickOutAllSessions", &ty.AuthenticateRequestArg{ | ||
err = client.Call("SessionAuth.KickOutAllSessions", &aty.AuthenticateRequestArg{ | ||
Token: loginResponse.Token, | ||
}, &voidResponse) | ||
if err != nil { | ||
t.Fatalf("Unable to remove all sessions: %s.\n", err.Error()) | ||
} | ||
|
||
// logout | ||
var logoutResponse ty.LogoutResponseArg | ||
err = client.Call("Login.Logout", &ty.LogoutRequestArg{ | ||
var logoutResponse aty.LogoutResponseArg | ||
err = client.Call("Login.Logout", &aty.LogoutRequestArg{ | ||
Token: loginResponse.Token, | ||
}, &logoutResponse) | ||
if err == nil { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.