Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] hashed default user password #307

Merged
merged 1 commit into from
Sep 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,10 @@ jobs:
- sudo apt-get update -q
- sudo apt-get install -qqy httpie bats nfs-kernel-server
- sudo pip install -U httpie-jwt-auth
- mkdir -p /tmp/nfs
- echo "/tmp/nfs *(rw,sync,no_root_squash)" | sudo tee /etc/exports
- sudo mkdir -p /nfsshare/mongodb
- sudo mkdir -p /nfsshare/influxdb
- sudo mkdir -p /nfsshare/user
- echo "/nfsshare *(rw,sync,no_root_squash)" | sudo tee /etc/exports
- sudo exportfs -r
- sudo showmount -e
script:
Expand Down
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ src.test-coverage-vagrant:
src.test-bats:
sed -i.bak "s/localhost:9090/$$(minikube ip):30003/g; s/localhost:27017/$$(minikube ip):31717/g" config/testing.json
./build/src/cmd/vortex/vortex -config config/testing.json -port 7890 &
@echo "Waiting for server startup"
sleep 1
@cd tests;\
./test.sh

Expand Down
3 changes: 2 additions & 1 deletion src/server/backend/authenticate.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package backend
import (
"github.com/linkernetworks/mongo"
"github.com/linkernetworks/vortex/src/entity"
"github.com/linkernetworks/vortex/src/utils"
"gopkg.in/mgo.v2/bson"
)

Expand All @@ -22,7 +23,7 @@ func Authenticate(session *mongo.Session, credential entity.LoginCredential) (en
return entity.User{}, false, err
}
hashedPassword := authenticatedUser.LoginCredential.Password
if CheckPasswordHash(credential.Password, hashedPassword) {
if utils.CheckPasswordHash(credential.Password, hashedPassword) {
return authenticatedUser, true, nil
}
return entity.User{}, false, nil
Expand Down
3 changes: 2 additions & 1 deletion src/server/backend/authenticate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/linkernetworks/vortex/src/config"
"github.com/linkernetworks/vortex/src/entity"
"github.com/linkernetworks/vortex/src/serviceprovider"
"github.com/linkernetworks/vortex/src/utils"
"github.com/stretchr/testify/suite"
"gopkg.in/mgo.v2/bson"
)
Expand All @@ -34,7 +35,7 @@ func (suite *AuthenticateTestSuite) SetupSuite() {

suite.plainTextPassword = "@uthentic@te"

hashedPassword, err := HashPassword(suite.plainTextPassword)
hashedPassword, err := utils.HashPassword(suite.plainTextPassword)
suite.NoError(err)

user := entity.User{
Expand Down
9 changes: 5 additions & 4 deletions src/server/handler_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
response "github.com/linkernetworks/vortex/src/net/http"
"github.com/linkernetworks/vortex/src/net/http/query"
"github.com/linkernetworks/vortex/src/server/backend"
"github.com/linkernetworks/vortex/src/utils"
"github.com/linkernetworks/vortex/src/web"

mgo "gopkg.in/mgo.v2"
Expand All @@ -27,12 +28,12 @@ func signUpUserHandler(ctx *web.Context) {
return
}

encryptedPassword, err := backend.HashPassword(user.LoginCredential.Password)
hashedPassword, err := utils.HashPassword(user.LoginCredential.Password)
if err != nil {
response.BadRequest(req.Request, resp.ResponseWriter, err)
return
}
user.LoginCredential.Password = encryptedPassword
user.LoginCredential.Password = hashedPassword

user.LoginCredential.Username = strings.ToLower(user.LoginCredential.Username)

Expand Down Expand Up @@ -133,12 +134,12 @@ func createUserHandler(ctx *web.Context) {
return
}

encryptedPassword, err := backend.HashPassword(user.LoginCredential.Password)
hashedPassword, err := utils.HashPassword(user.LoginCredential.Password)
if err != nil {
response.BadRequest(req.Request, resp.ResponseWriter, err)
return
}
user.LoginCredential.Password = encryptedPassword
user.LoginCredential.Password = hashedPassword

user.LoginCredential.Username = strings.ToLower(user.LoginCredential.Username)

Expand Down
7 changes: 6 additions & 1 deletion src/serviceprovider/default_admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,22 @@ import (
"github.com/linkernetworks/mongo"
"github.com/linkernetworks/utils/timeutils"
"github.com/linkernetworks/vortex/src/entity"
"github.com/linkernetworks/vortex/src/utils"
"gopkg.in/mgo.v2/bson"
)

func createDefaultUser(mongoService *mongo.Service) error {
session := mongoService.NewSession()
defer session.Close()
hashedPassword, err := utils.HashPassword("password")
if err != nil {
return err
}
user := entity.User{
ID: bson.NewObjectId(),
LoginCredential: entity.LoginCredential{
Username: "[email protected]",
Password: "password",
Password: hashedPassword,
},
DisplayName: "administrator",
Role: "root",
Expand Down
2 changes: 1 addition & 1 deletion src/server/backend/password.go → src/utils/password.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package backend
package utils

import (
"golang.org/x/crypto/bcrypt"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package backend
package utils

import (
"testing"
Expand Down
2 changes: 1 addition & 1 deletion tests/00-environement/00-env.bats
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@
}

@test "Check NFS server setting" {
showmount -e | grep /tmp/nfs ; echo $?
showmount -e | grep /nfsshare ; echo $?
[ $? = 0 ]
}
10 changes: 0 additions & 10 deletions tests/01-signin-signup/user.json

This file was deleted.

2 changes: 1 addition & 1 deletion tests/04-storage-pod/script.bats
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ load init

@test "Test NFS" {
kubectl exec ${podName} touch /tmp/testing
find /tmp/nfs | grep testing
find /nfsshare | grep testing
[ $? = 0 ]
}

Expand Down
2 changes: 1 addition & 1 deletion tests/04-storage-pod/storage.info
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"type": "nfs",
"name": "@NFSSTORAGENAME@",
"ip":"@NFSIP@",
"path":"/tmp/nfs"
"path":"/nfsshare"
}