-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ConnectPacketBuilder - can noe return error (prevents connection atte…
…mpt) `ConnectPacketBuilder` may be used to retrieve a token for use in auth, it's may not always be possible to retrieve this token so this change enables `ConnectPacketBuilder` to return an error (which prevents the current attempt, another attempt will be made after a delay).
- Loading branch information
Showing
3 changed files
with
56 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -552,7 +552,7 @@ func TestClientConfig_buildConnectPacket(t *testing.T) { | |
} | ||
|
||
// Validate initial state | ||
cp := config.buildConnectPacket(true, nil) | ||
cp, _ := config.buildConnectPacket(true, nil) | ||
|
||
if !cp.CleanStart { | ||
t.Errorf("Expected Clean Start to be true") | ||
|
@@ -573,7 +573,7 @@ func TestClientConfig_buildConnectPacket(t *testing.T) { | |
config.SetUsernamePassword("testuser", []byte("testpassword")) | ||
config.SetWillMessage(fmt.Sprintf("client/%s/state", config.ClientID), []byte("disconnected"), 1, true) | ||
|
||
cp = config.buildConnectPacket(false, nil) | ||
cp, _ = config.buildConnectPacket(false, nil) | ||
if cp.CleanStart { | ||
t.Errorf("Expected Clean Start to be false") | ||
} | ||
|
@@ -609,14 +609,14 @@ func TestClientConfig_buildConnectPacket(t *testing.T) { | |
} | ||
|
||
// Set an override method for the CONNECT packet | ||
config.SetConnectPacketConfigurator(func(c *paho.Connect) *paho.Connect { | ||
config.SetConnectPacketConfigurator(func(c *paho.Connect) (*paho.Connect, error) { | ||
delay := uint32(200) | ||
c.WillProperties.WillDelayInterval = &delay | ||
return c | ||
return c, nil | ||
}) | ||
|
||
testUrl, _ := url.Parse("mqtt://mqtt_user:[email protected]:1883") | ||
cp = config.buildConnectPacket(false, testUrl) | ||
cp, _ = config.buildConnectPacket(false, testUrl) | ||
|
||
if *(cp.WillProperties.WillDelayInterval) != 200 { // verifies the override | ||
t.Errorf("Will message Delay Interval did not match expected [200]: found [%v]", *(cp.Properties.WillDelayInterval)) | ||
|
@@ -634,15 +634,15 @@ func ExampleClientConfig_ConnectPacketBuilder() { | |
ClientID: "test", | ||
}, | ||
} | ||
config.ConnectPacketBuilder = func(c *paho.Connect, u *url.URL) *paho.Connect { | ||
config.ConnectPacketBuilder = func(c *paho.Connect, u *url.URL) (*paho.Connect, error) { | ||
// Extracting password from URL | ||
c.Username = u.User.Username() | ||
// up to user to catch empty password passed via URL | ||
p, _ := u.User.Password() | ||
c.Password = []byte(p) | ||
return c | ||
return c, nil | ||
} | ||
cp := config.buildConnectPacket(false, serverURL) | ||
cp, _ := config.buildConnectPacket(false, serverURL) | ||
fmt.Printf("user: %s, pass: %s", cp.Username, string(cp.Password)) | ||
// Output: user: mqtt_user, pass: mqtt_pass | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters