Skip to content
Open
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
2 changes: 1 addition & 1 deletion docs/ocpp1.6-security-extension.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Example central system:

```go
server := ws.NewServer()
server.SetBasicAuthHandler(func (username string, password string) bool {
server.SetBasicAuthHandler(func (chargePointID string, username string, password string) bool {
// todo Handle basic auth
return true
})
Expand Down
10 changes: 5 additions & 5 deletions ws/mocks/mock_Server.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions ws/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ type Server interface {
// SetBasicAuthHandler enables HTTP Basic Authentication and requires clients to pass credentials.
// The handler function is called whenever a new client attempts to connect, to check for credentials correctness.
// The handler must return true if the credentials were correct, false otherwise.
SetBasicAuthHandler(handler func(username string, password string) bool)
SetBasicAuthHandler(handler func(chargePointID string, username string, password string) bool)
// SetCheckOriginHandler sets a handler for incoming websocket connections, allowing to perform
// custom cross-origin checks.
//
Expand Down Expand Up @@ -137,7 +137,7 @@ type server struct {
checkClientHandler CheckClientHandler
newClientHandler func(ws Channel)
disconnectedHandler func(ws Channel)
basicAuthHandler func(username string, password string) bool
basicAuthHandler func(chargePointID string, username string, password string) bool
tlsCertificatePath string
tlsCertificateKey string
timeoutConfig ServerTimeoutConfig
Expand Down Expand Up @@ -232,7 +232,7 @@ func (s *server) SetChargePointIdResolver(resolver func(r *http.Request) (string
s.chargePointIdResolver = resolver
}

func (s *server) SetBasicAuthHandler(handler func(username string, password string) bool) {
func (s *server) SetBasicAuthHandler(handler func(chargePointID string, username string, password string) bool) {
s.basicAuthHandler = handler
}

Expand Down Expand Up @@ -387,7 +387,7 @@ out:
if s.basicAuthHandler != nil {
username, password, ok := r.BasicAuth()
if ok {
ok = s.basicAuthHandler(username, password)
ok = s.basicAuthHandler(id, username, password)
}
if !ok {
s.error(fmt.Errorf("basic auth failed: credentials invalid"))
Expand Down
7 changes: 4 additions & 3 deletions ws/websocket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,8 @@ func (s *WebSocketSuite) TestValidBasicAuth() {
s.server, ok = tlsServer.(*server)
s.True(ok)
// Add basic auth handler
s.server.SetBasicAuthHandler(func(username string, password string) bool {
s.server.SetBasicAuthHandler(func(chargePointID string, username string, password string) bool {
s.Equal(testPath, chargePointID)
s.Equal(authUsername, username)
s.Equal(authPassword, password)
return true
Expand Down Expand Up @@ -804,8 +805,8 @@ func (s *WebSocketSuite) TestInvalidBasicAuth() {
s.server, ok = tlsServer.(*server)
s.True(ok)
// Add basic auth handler
s.server.SetBasicAuthHandler(func(username string, password string) bool {
validCredentials := authUsername == username && authPassword == password
s.server.SetBasicAuthHandler(func(chargePointID string, username string, password string) bool {
validCredentials := testPath == chargePointID && authUsername == username && authPassword == password
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests are failing because the check should only be against testsws and not the full testPath. Would merge once this is fixed.

s.False(validCredentials)
return validCredentials
})
Expand Down
Loading