File: account_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 (103 lines) | stat: -rw-r--r-- 3,145 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package config

import (
	"github.com/twstrike/otr3"

	. "gopkg.in/check.v1"
)

type AccountXmppSuite struct{}

var _ = Suite(&AccountXmppSuite{})

func (s *AccountXmppSuite) Test_Account_Is_recognizesJids(c *C) {
	a := &Account{Account: "hello@bar.com"}
	c.Check(a.Is("foo"), Equals, false)
	c.Check(a.Is("hello@bar.com"), Equals, true)
	c.Check(a.Is("hello@bar.com/foo"), Equals, true)
}

func (s *AccountXmppSuite) Test_Account_ShouldEncryptTo(c *C) {
	a := &Account{Account: "hello@bar.com", AlwaysEncrypt: false, AlwaysEncryptWith: []string{"one@foo.com", "two@foo.com"}}
	a2 := &Account{Account: "hello@bar.com", AlwaysEncrypt: true, AlwaysEncryptWith: []string{"one@foo.com", "two@foo.com"}}
	c.Check(a.ShouldEncryptTo("foo"), Equals, false)
	c.Check(a.ShouldEncryptTo("hello@bar.com"), Equals, false)
	c.Check(a.ShouldEncryptTo("one@foo.com"), Equals, true)
	c.Check(a.ShouldEncryptTo("two@foo.com"), Equals, true)
	c.Check(a.ShouldEncryptTo("two@foo.com/blarg"), Equals, true)
	c.Check(a2.ShouldEncryptTo("foo"), Equals, true)
	c.Check(a2.ShouldEncryptTo("hello@bar.com"), Equals, true)
}

func (s *AccountXmppSuite) Test_NewAccount_ReturnsNewAccountWithSafeDefaults(c *C) {
	a, err := NewAccount()

	c.Check(err, IsNil)
	c.Check(len(a.PrivateKeys), Equals, 1)
	c.Check(a.AlwaysEncrypt, Equals, true)
	c.Check(a.OTRAutoStartSession, Equals, true)
	c.Check(a.OTRAutoTearDown, Equals, true)
	c.Check(a.Proxies, DeepEquals, []string{"tor-auto://"})
}

func (s *AccountXmppSuite) Test_SetOTRPoliciesFor_SetupOTRPolicies(c *C) {
	a, _ := NewAccount()
	conv := &otr3.Conversation{}

	expectedConv := &otr3.Conversation{}
	expectedPolicies := expectedConv.Policies
	expectedPolicies.AllowV2()
	expectedPolicies.AllowV3()
	expectedPolicies.SendWhitespaceTag()
	expectedPolicies.WhitespaceStartAKE()
	expectedPolicies.RequireEncryption()
	expectedPolicies.ErrorStartAKE()

	a.SetOTRPoliciesFor("someon@jabber.com", conv)
	c.Check(conv.Policies, Equals, expectedPolicies)
}

func (s *AccountXmppSuite) Test_SetOTRPoliciesFor_SetupOTRPoliciesWithOptionalEncription(c *C) {
	a, _ := NewAccount()
	a.AlwaysEncrypt = false
	conv := &otr3.Conversation{}

	expectedConv := &otr3.Conversation{}
	expectedPolicies := expectedConv.Policies
	expectedPolicies.AllowV2()
	expectedPolicies.AllowV3()
	expectedPolicies.SendWhitespaceTag()
	expectedPolicies.WhitespaceStartAKE()

	a.SetOTRPoliciesFor("someon@jabber.com", conv)
	c.Check(conv.Policies, Equals, expectedPolicies)
}

func (s *AccountXmppSuite) Test_EnsurePrivateKey_DoesNotUpdateIfKeyExists(c *C) {
	a, _ := NewAccount()
	changed, err := a.EnsurePrivateKey()

	c.Check(err, IsNil)
	c.Check(changed, Equals, false)
}

func (s *AccountXmppSuite) Test_EnsurePrivateKey_GeneratePrivateKeyIfMissing(c *C) {
	a := &Account{}
	changed, err := a.EnsurePrivateKey()

	c.Check(err, IsNil)
	c.Check(changed, Equals, true)
	c.Check(len(a.PrivateKeys), Equals, 1)
}

func (s *AccountXmppSuite) Test_ID_generatesID(c *C) {
	a := &Account{}
	c.Check(a.ID(), Not(HasLen), 0)
}

func (s *AccountXmppSuite) Test_ID_doesNotChangeID(c *C) {
	a := &Account{
		id: "existing",
	}
	c.Check(a.ID(), Equals, "existing")
}