forked from Zhuguoping/jackal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauth_test.go
48 lines (37 loc) · 1.47 KB
/
auth_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
* Copyright (c) 2018 Miguel Ángel Ortuño.
* See the LICENSE file for more information.
*/
package auth
import (
"testing"
"github.com/ortuman/jackal/model"
"github.com/ortuman/jackal/storage"
"github.com/ortuman/jackal/storage/memstorage"
"github.com/ortuman/jackal/stream"
"github.com/ortuman/jackal/xmpp/jid"
"github.com/pborman/uuid"
"github.com/stretchr/testify/require"
)
func authTestSetup(user *model.User) (*stream.MockC2S, *memstorage.Storage) {
s := memstorage.New()
storage.Set(s)
storage.InsertOrUpdateUser(user)
j, _ := jid.New("mariana", "localhost", "res", true)
testStm := stream.NewMockC2S(uuid.New(), j)
testStm.SetJID(j)
return testStm, s
}
func authTestTeardown() {
storage.Unset()
}
func TestAuthError(t *testing.T) {
require.Equal(t, "incorrect-encoding", ErrSASLIncorrectEncoding.(*SASLError).Error())
require.Equal(t, "malformed-request", ErrSASLMalformedRequest.(*SASLError).Error())
require.Equal(t, "not-authorized", ErrSASLNotAuthorized.(*SASLError).Error())
require.Equal(t, "temporary-auth-failure", ErrSASLTemporaryAuthFailure.(*SASLError).Error())
require.Equal(t, "incorrect-encoding", ErrSASLIncorrectEncoding.(*SASLError).Element().Name())
require.Equal(t, "malformed-request", ErrSASLMalformedRequest.(*SASLError).Element().Name())
require.Equal(t, "not-authorized", ErrSASLNotAuthorized.(*SASLError).Element().Name())
require.Equal(t, "temporary-auth-failure", ErrSASLTemporaryAuthFailure.(*SASLError).Element().Name())
}