-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3c0f769
commit 2238d80
Showing
3 changed files
with
75 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package command | ||
|
||
import ( | ||
"fmt" | ||
"github.com/ProtonMail/gluon/imap/parser" | ||
) | ||
|
||
type LoginCommand struct { | ||
UserID string | ||
Password string | ||
} | ||
|
||
func (l LoginCommand) String() string { | ||
return fmt.Sprintf("LOGIN '%v' '%v'", l.UserID, l.Password) | ||
} | ||
|
||
func (l LoginCommand) SanitizedString() string { | ||
return fmt.Sprintf("LOGIN '%v' <PASSWORD>", sanitizeString(l.UserID)) | ||
} | ||
|
||
type LoginCommandParser struct{} | ||
|
||
func (LoginCommandParser) FromParser(p *parser.Parser) (Payload, error) { | ||
// login = "LOGIN" SP userid SP password | ||
// userid = astring | ||
// password = astring | ||
if err := p.Consume(parser.TokenTypeSP, "expected space after command"); err != nil { | ||
return nil, err | ||
} | ||
|
||
user, err := p.ParseAString() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if err := p.Consume(parser.TokenTypeSP, "expected space after userid"); err != nil { | ||
return nil, err | ||
} | ||
|
||
password, err := p.ParseAString() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &LoginCommand{ | ||
UserID: user, | ||
Password: password, | ||
}, nil | ||
} |
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,25 @@ | ||
package command | ||
|
||
import ( | ||
"bytes" | ||
"github.com/ProtonMail/gluon/imap/parser" | ||
"github.com/stretchr/testify/require" | ||
"testing" | ||
) | ||
|
||
func TestParser_LoginCommandQuoted(t *testing.T) { | ||
input := toIMAPLine(`tag LOGIN "foo" "bar"`) | ||
s := parser.NewScanner(bytes.NewReader(input)) | ||
p := NewParser(s) | ||
|
||
expected := Command{Tag: "tag", Payload: &LoginCommand{ | ||
UserID: "foo", | ||
Password: "bar", | ||
}} | ||
|
||
cmd, err := p.Parse() | ||
require.NoError(t, err) | ||
require.Equal(t, expected, cmd) | ||
require.Equal(t, "login", p.LastParsedCommand()) | ||
require.Equal(t, "tag", p.LastParsedTag()) | ||
} |
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