File: sasl_test.go

package info (click to toggle)
coyim 0.3.7-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 4,064 kB
  • ctags: 4,528
  • sloc: xml: 5,120; sh: 328; python: 286; makefile: 235; ruby: 51
file content (77 lines) | stat: -rw-r--r-- 1,730 bytes parent folder | download
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package sasl

import (
	"io/ioutil"
	"log"
	"testing"

	"github.com/twstrike/gotk3adapter/glib_mock"
	"github.com/twstrike/coyim/i18n"

	. "gopkg.in/check.v1"
)

func Test(t *testing.T) { TestingT(t) }

func init() {
	log.SetOutput(ioutil.Discard)
	i18n.InitLocalization(&glib_mock.Mock{})
}

type SASLSuite struct{}

var _ = Suite(&SASLSuite{})

type testMechanism struct {
	s Session
}

func (tm *testMechanism) NewClient() Session {
	return tm.s
}

func (s *SASLSuite) Test_RegisterMechanism_registeringTheSameMechanismTwiceReturnsAnError(c *C) {
	val := RegisterMechanism("foo", &testMechanism{nil})
	val2 := RegisterMechanism("foo", &testMechanism{nil})
	c.Assert(val, IsNil)
	c.Assert(val2, Equals, ErrMechanismAlreadyRegistered)
}

func (s *SASLSuite) Test_ClientSupport_returnsFalseForUnsupportedMechansim(c *C) {
	val := ClientSupport("foo2")
	c.Assert(val, Equals, false)
}

func (s *SASLSuite) Test_ClientSupport_returnsFalseForRegisteredMechanism(c *C) {
	RegisterMechanism("foo3", &testMechanism{nil})
	val := ClientSupport("foo3")
	c.Assert(val, Equals, true)
}

func (s *SASLSuite) Test_NewClient_returnsErrorForUnsupportedMechanism(c *C) {
	ss, err := NewClient("foo4")
	c.Assert(ss, IsNil)
	c.Assert(err, Equals, ErrUnsupportedMechanism)
}

type testSession struct{}

func (*testSession) SetProperty(Property, string) error {
	return nil
}

func (*testSession) Step(Token) (Token, error) {
	return nil, nil
}

func (*testSession) NeedsMore() bool {
	return false
}

func (s *SASLSuite) Test_NewClient_returnsTheResultOfNewClientForSupportedMechanism(c *C) {
	sess := &testSession{}
	RegisterMechanism("foo5", &testMechanism{sess})
	ss, err := NewClient("foo5")
	c.Assert(err, IsNil)
	c.Assert(ss, Equals, sess)
}