File: security_events_test.go

package info (click to toggle)
golang-github-twstrike-otr3 0.0~git20161015.0.744856d-3.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 1,080 kB
  • sloc: ansic: 127; makefile: 76
file content (36 lines) | stat: -rw-r--r-- 1,166 bytes parent folder | download | duplicates (3)
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
package otr3

import "testing"

func Test_SecurityEvent_hasValidStringImplementation(t *testing.T) {
	assertEquals(t, GoneInsecure.String(), "GoneInsecure")
	assertEquals(t, GoneSecure.String(), "GoneSecure")
	assertEquals(t, StillSecure.String(), "StillSecure")
	assertEquals(t, SecurityEvent(20000).String(), "SECURITY EVENT: (THIS SHOULD NEVER HAPPEN)")
}

func Test_combinedSecurityEventHandler_callsAllSecurityEventHandlersGiven(t *testing.T) {
	var called1, called2, called3 bool
	f1 := dynamicSecurityEventHandler{func(event SecurityEvent) {
		called1 = true
	}}
	f2 := dynamicSecurityEventHandler{func(event SecurityEvent) {
		called2 = true
	}}
	f3 := dynamicSecurityEventHandler{func(event SecurityEvent) {
		called3 = true
	}}
	d := CombineSecurityEventHandlers(f1, nil, f2, f3)
	d.HandleSecurityEvent(GoneSecure)

	assertEquals(t, called1, true)
	assertEquals(t, called2, true)
	assertEquals(t, called3, true)
}

func Test_debugSecurityEventHandler_writesTheEventToStderr(t *testing.T) {
	ss := captureStderr(func() {
		DebugSecurityEventHandler{}.HandleSecurityEvent(StillSecure)
	})
	assertEquals(t, ss, "[DEBUG] HandleSecurityEvent(StillSecure)\n")
}