Example #1
0
// Verify that keypresses are read properly.
func TestKeypresses(t *testing.T) {
	testfe := testfrontend.NewTestFrontend()
	frontend := OpenFrontendish(testfe)
	testfe.FillBuffer("^PAD 2  $^PAD 3  $^PAD 4  $^PAD 5  $^PAD #  $")

	// Trigger a timeout after 0.5s
	timeout := make(chan bool)
	go func() {
		time.Sleep(500 * time.Millisecond)
		timeout <- true
	}()

	// Now verify that we receive the key presses we put in the buffer earlier.
	var keypressBuffer bytes.Buffer

	for {
		select {
		case <-timeout:
			t.Error("Did not receive the expected keypresses within 0.5s\n")
			return
		case keypress := <-frontend.Keypresses:
			b := []byte(keypress.Key)
			keypressBuffer.WriteByte(b[0])
			if keypressBuffer.String() == "2345#" {
				return
			}
		}
	}
}
Example #2
0
func TestPinValidation(t *testing.T) {
	testfe := testfrontend.NewTestFrontend()
	frontend := frontend.OpenFrontendish(testfe)

	pins := pinstore.Load("/tmp/testcase")
	pins.Pins["123456"] = "secure"

	hometec := make(chan string)
	go ValidatePin(pins, frontend, hometec)

	invalidPin := constructPinBuffer("1234")
	validPin := constructPinBuffer("123456")

	if _, ok := resultWithBuffer(testfe, invalidPin, hometec); ok {
		t.Error("Hometec got an instruction for an invalid pin")
	}

	if _, ok := resultWithBuffer(testfe, validPin, hometec); ok {
		t.Error("Hometec got an instruction for an invalid pin")
	}
}