gravitl / netmaker

Netmaker makes networks with WireGuard. Netmaker automates fast, secure, and distributed virtual networks.
https://netmaker.io
Other
9.4k stars 547 forks source link

Panic when deleting a non-existance admin (either one that has already been deleted or one that never existed) #27

Closed mattkasun closed 3 years ago

mattkasun commented 3 years ago

deleting a non-existent admin results in a panic. The panic doesn't crash, i.e. backend recovers and tool is still usable.
Should add error handling instead of panic.

mkasun@firefly:~/sandbox/netmaker$ go run . &
[1] 16186
mkasun@firefly:~/sandbox/netmaker$ 2021/03/28 17:45:05 Server starting...
2021/03/28 17:45:05 Database connecting...
2021/03/28 17:45:05 Database Connected.
REST Server succesfully started on port 8081 (REST)
Agent Server succesfully started on port :50051 (gRPC)
deleteWrongAdmin.sh 
2021/03/28 17:45:13 server.go:3139: http: panic serving 127.0.0.1:53442: runtime error: invalid memory address or nil pointer dereference
goroutine 23 [running]:
net/http.(*conn).serve.func1(0xc0003ed5e0)
    /snap/go/7221/src/net/http/server.go:1824 +0x153
panic(0xcd3300, 0x13f7500)
    /snap/go/7221/src/runtime/panic.go:971 +0x499
github.com/gravitl/netmaker/controllers.deleteUser(0xfc3630, 0xc00039a1c0, 0xc0002dee00)
    /home/mkasun/sandbox/netmaker/controllers/userHttpController.go:448 +0x189
net/http.HandlerFunc.ServeHTTP(0xde7928, 0xfc3630, 0xc00039a1c0, 0xc0002dee00)
    /snap/go/7221/src/net/http/server.go:2069 +0x44
github.com/gravitl/netmaker/controllers.authorizeUser.func1(0xfc3630, 0xc00039a1c0, 0xc0002dee00)
    /home/mkasun/sandbox/netmaker/controllers/userHttpController.go:175 +0x1f0
net/http.HandlerFunc.ServeHTTP(0xc00000eff0, 0xfc3630, 0xc00039a1c0, 0xc0002dee00)
    /snap/go/7221/src/net/http/server.go:2069 +0x44
github.com/gorilla/mux.(*Router).ServeHTTP(0xc0001029c0, 0xfc3630, 0xc00039a1c0, 0xc0002dec00)
    /home/mkasun/go/pkg/mod/github.com/gorilla/mux@v1.8.0/mux.go:210 +0xd3
github.com/gorilla/handlers.(*cors).ServeHTTP(0xc0003bcea0, 0xfc3630, 0xc00039a1c0, 0xc0002dec00)
    /home/mkasun/go/pkg/mod/github.com/gorilla/handlers@v1.5.1/cors.go:54 +0x103e
net/http.serverHandler.ServeHTTP(0xc00039a0e0, 0xfc3630, 0xc00039a1c0, 0xc0002dec00)
    /snap/go/7221/src/net/http/server.go:2887 +0xa3
net/http.(*conn).serve(0xc0003ed5e0, 0xfc4300, 0xc0003da340)
    /snap/go/7221/src/net/http/server.go:1952 +0x8cd
created by net/http.(*Server).Serve
    /snap/go/7221/src/net/http/server.go:3013 +0x39b
curl: (52) Empty reply from server
mkasun@firefly:~/sandbox/netmaker$ cat ~/bin/deleteWrongAdmin.sh 
#!/bin/bash

curl -X DELETE -H "authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJJc0FkbWluIjp0cnVlLCJVc2VyTmFtZSI6ImFkbWluIiwiZXhwIjoxNjE2Nzg5ODg1fQ.YwzicKnNZ4GtnyYdzF90gSt_efy6MVNLQ1PLNuBQfOM" -H "Content-Type: application/json"  http://localhost:8081/users/xxxx -D 

mkasun@firefly:~/sandbox/netmaker$ cat ~/bin/deleteNoAdmin.sh 
#!/bin/bash

curl -X DELETE -H "authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJJc0FkbWluIjp0cnVlLCJVc2VyTmFtZSI6ImFkbWluIiwiZXhwIjoxNjE2Nzg5ODg1fQ.YwzicKnNZ4GtnyYdzF90gSt_efy6MVNLQ1PLNuBQfOM" -H "Content-Type: application/json"  http://localhost:8081/users/admin -D -

curl -X DELETE -H "authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJJc0FkbWluIjp0cnVlLCJVc2VyTmFtZSI6ImFkbWluIiwiZXhwIjoxNjE2Nzg5ODg1fQ.YwzicKnNZ4GtnyYdzF90gSt_efy6MVNLQ1PLNuBQfOM" -H "Content-Type: application/json"  http://localhost:8081/users/admin -D -
afeiszli commented 3 years ago

adding to v0.2 fix list

afeiszli commented 3 years ago

Fixed in latest commit. Will close when merged with develop and list PR.

afeiszli commented 3 years ago

closed with #95