-
Notifications
You must be signed in to change notification settings - Fork 537
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #192 from vaelen/master
Add a way to set the username and password via callback.
- Loading branch information
Showing
3 changed files
with
76 additions
and
4 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
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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright (c) 2013 IBM Corp. | ||
* | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Andrew Young | ||
*/ | ||
|
||
package mqtt | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func Test_UsernamePassword(t *testing.T) { | ||
options := NewClientOptions() | ||
options.Username = "username" | ||
options.Password = "password" | ||
|
||
m := newConnectMsgFromOptions(options) | ||
|
||
if m.Username != "username" { | ||
t.Fatalf("Username not set correctly") | ||
} | ||
|
||
if string(m.Password) != "password" { | ||
t.Fatalf("Password not set correctly") | ||
} | ||
} | ||
|
||
func Test_CredentialsProvider(t *testing.T) { | ||
options := NewClientOptions() | ||
options.Username = "incorrect" | ||
options.Password = "incorrect" | ||
options.SetCredentialsProvider(func() (username string, password string) { | ||
return "username", "password" | ||
}) | ||
|
||
m := newConnectMsgFromOptions(options) | ||
|
||
if m.Username != "username" { | ||
t.Fatalf("Username not set correctly") | ||
} | ||
|
||
if string(m.Password) != "password" { | ||
t.Fatalf("Password not set correctly") | ||
} | ||
} |