Skip to content

Commit

Permalink
fix issue with creating a new user
Browse files Browse the repository at this point in the history
  • Loading branch information
wardviaene committed Aug 27, 2024
1 parent 06c6390 commit a78b6cc
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ install-digitalocean:
cd provisioning && packer build packer-digitalocean-amd64.pkr.hcl

install-s3:
cd provisioning && AWS_PROFILE=in4it-vpn-server scripts/install_s3.sh
cd provisioning && AWS_PROFILE=in4it-vpn-server scripts/install_s3.sh --release

install-docs:
provisioning/scripts/deploy_documentation.sh
2 changes: 1 addition & 1 deletion latest
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v1.1.1
v1.1.2
6 changes: 6 additions & 0 deletions pkg/rest/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,9 @@ type UserStatsDataPoint struct {
X string `json:"x"`
Y float64 `json:"y"`
}

type NewUserRequest struct {
Login string `json:"login"`
Role string `json:"role"`
Password string `json:"password,omitempty"`
}
2 changes: 1 addition & 1 deletion pkg/rest/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (c *Context) usersHandler(w http.ResponseWriter, r *http.Request) {
}
c.write(w, out)
case http.MethodPost:
var user users.User
var user NewUserRequest
decoder := json.NewDecoder(r.Body)
err := decoder.Decode(&user)
if err != nil {
Expand Down
36 changes: 36 additions & 0 deletions pkg/rest/users_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,39 @@ func TestCreateUserConnectionDeleteUserFlow(t *testing.T) {
t.Fatalf("could read user config file, expected not to")
}
}

func TestCreateUser(t *testing.T) {
// first create a new user
storage := &testingmocks.MockMemoryStorage{}

c, err := newContext(storage, SERVER_TYPE_VPN)
if err != nil {
t.Fatalf("Cannot create context")
}

err = c.UserStore.Empty()
if err != nil {
t.Fatalf("Cannot create context")
}

// create a user
payload := []byte(`{"id": "", "login": "testuser", "password": "tttt213", "role": "user", "oidcID": "", "samlID": "", "lastLogin": "", "provisioned": false, "role":"user","samlID":"","suspended":false}`)
req := httptest.NewRequest("POST", "http://example.com/users", bytes.NewBuffer(payload))
w := httptest.NewRecorder()
c.usersHandler(w, req)

resp := w.Result()

if resp.StatusCode != 200 {
t.Fatalf("status code is not 200: %d", resp.StatusCode)
}

defer resp.Body.Close()

var user users.User
err = json.NewDecoder(resp.Body).Decode(&user)
if err != nil {
t.Fatalf("Cannot decode response from create user: %s", err)
}

}
2 changes: 1 addition & 1 deletion pkg/users/localusers.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

func (u *UserStore) AddUser(user User) (User, error) {
if user.Login == "" {
return user, fmt.Errorf("Login cannot be empty")
return user, fmt.Errorf("login cannot be empty")
}
existingUsers := u.ListUsers()
for _, existingUser := range existingUsers {
Expand Down
1 change: 1 addition & 0 deletions pkg/users/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type User struct {
ExternalID string `json:"externalID,omitempty"`
LastLogin time.Time `json:"lastLogin"`
}

type Factor struct {
Name string `json:"name"`
Type string `json:"type"`
Expand Down
2 changes: 1 addition & 1 deletion provisioning/scripts/install_s3.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ aws s3 cp ../configmanager-linux-amd64 s3://in4it-vpn-server/assets/binaries/${L
aws s3 cp ../configmanager-linux-amd64.sha256 s3://in4it-vpn-server/assets/binaries/${LATEST}/configmanager-linux-amd64.sha256
if [ "$1" == "--release" ] ; then
echo "=> $LATEST released."
#aws s3 cp ../latest s3://in4it-vpn-server/assets/binaries/latest
aws s3 cp ../latest s3://in4it-vpn-server/assets/binaries/latest
fi

0 comments on commit a78b6cc

Please sign in to comment.