Skip to content

Commit 17cf26d

Browse files
committed
pass the chargepoint id to basic auth handler
1 parent 1884a51 commit 17cf26d

File tree

4 files changed

+15
-14
lines changed

4 files changed

+15
-14
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ Example central system:
380380

381381
```go
382382
server := ws.NewServer()
383-
server.SetBasicAuthHandler(func (username string, password string) bool {
383+
server.SetBasicAuthHandler(func (chargePointID string, username string, password string) bool {
384384
// todo Handle basic auth
385385
return true
386386
})

ws/mocks/mock_Server.go

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ws/server.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ type Server interface {
100100
// SetBasicAuthHandler enables HTTP Basic Authentication and requires clients to pass credentials.
101101
// The handler function is called whenever a new client attempts to connect, to check for credentials correctness.
102102
// The handler must return true if the credentials were correct, false otherwise.
103-
SetBasicAuthHandler(handler func(username string, password string) bool)
103+
SetBasicAuthHandler(handler func(chargePointID string, username string, password string) bool)
104104
// SetCheckOriginHandler sets a handler for incoming websocket connections, allowing to perform
105105
// custom cross-origin checks.
106106
//
@@ -133,7 +133,7 @@ type server struct {
133133
checkClientHandler CheckClientHandler
134134
newClientHandler func(ws Channel)
135135
disconnectedHandler func(ws Channel)
136-
basicAuthHandler func(username string, password string) bool
136+
basicAuthHandler func(chargePointID string, username string, password string) bool
137137
tlsCertificatePath string
138138
tlsCertificateKey string
139139
timeoutConfig ServerTimeoutConfig
@@ -220,7 +220,7 @@ func (s *server) AddSupportedSubprotocol(subProto string) {
220220
s.upgrader.Subprotocols = append(s.upgrader.Subprotocols, subProto)
221221
}
222222

223-
func (s *server) SetBasicAuthHandler(handler func(username string, password string) bool) {
223+
func (s *server) SetBasicAuthHandler(handler func(chargePointID string, username string, password string) bool) {
224224
s.basicAuthHandler = handler
225225
}
226226

@@ -371,7 +371,7 @@ out:
371371
if s.basicAuthHandler != nil {
372372
username, password, ok := r.BasicAuth()
373373
if ok {
374-
ok = s.basicAuthHandler(username, password)
374+
ok = s.basicAuthHandler(id, username, password)
375375
}
376376
if !ok {
377377
s.error(fmt.Errorf("basic auth failed: credentials invalid"))

ws/websocket_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,8 @@ func (s *WebSocketSuite) TestValidBasicAuth() {
691691
s.server, ok = tlsServer.(*server)
692692
s.True(ok)
693693
// Add basic auth handler
694-
s.server.SetBasicAuthHandler(func(username string, password string) bool {
694+
s.server.SetBasicAuthHandler(func(chargePointID string, username string, password string) bool {
695+
s.Equal(testPath, chargePointID)
695696
s.Equal(authUsername, username)
696697
s.Equal(authPassword, password)
697698
return true
@@ -746,8 +747,8 @@ func (s *WebSocketSuite) TestInvalidBasicAuth() {
746747
s.server, ok = tlsServer.(*server)
747748
s.True(ok)
748749
// Add basic auth handler
749-
s.server.SetBasicAuthHandler(func(username string, password string) bool {
750-
validCredentials := authUsername == username && authPassword == password
750+
s.server.SetBasicAuthHandler(func(chargePointID string, username string, password string) bool {
751+
validCredentials := testPath == chargePointID && authUsername == username && authPassword == password
751752
s.False(validCredentials)
752753
return validCredentials
753754
})
@@ -1276,7 +1277,7 @@ func (s *WebSocketSuite) TestClientErrors() {
12761277
conn := s.server.connections[path.Base(testPath)]
12771278
s.NotNil(conn)
12781279
err = conn.WriteManual(websocket.CloseMessage, websocket.FormatCloseMessage(websocket.CloseUnsupportedData, ""))
1279-
//err = conn.connection.WriteMessage(websocket.CloseMessage, websocket.FormatCloseMessage(websocket.CloseUnsupportedData, ""))
1280+
// err = conn.connection.WriteMessage(websocket.CloseMessage, websocket.FormatCloseMessage(websocket.CloseUnsupportedData, ""))
12801281
s.NoError(err)
12811282
r = <-triggerC
12821283
s.NotNil(r)

0 commit comments

Comments
 (0)