예제 #1
0
파일: crypto_test.go 프로젝트: qbit/client
func TestCryptoSecretUI(t *testing.T) {
	tc := libkb.SetupTest(t, "crypto", 2)
	defer tc.Cleanup()

	c := NewCryptoHandler(tc.G)

	// Should return errorSecretUI because UIRouter returned an
	// error.
	tc.G.SetUIRouter(fakeUIRouter{secretUIErr: errors.New("fake error")})
	secretUI := c.getSecretUI(0, "")
	if _, ok := secretUI.(errorSecretUI); !ok {
		t.Errorf("secretUI %v is not an errorSecretUI", secretUI)
	}

	// Should return errorSecretUI because UIRouter returned nil.
	tc.G.SetUIRouter(fakeUIRouter{})
	secretUI = c.getSecretUI(0, "")
	if _, ok := secretUI.(errorSecretUI); !ok {
		t.Errorf("secretUI %v is not an errorSecretUI", secretUI)
	}

	// Should return nullSecretUI..
	tc.G.SetUIRouter(fakeUIRouter{secretUI: nullSecretUI{}})
	secretUI = c.getSecretUI(0, "")
	if _, ok := secretUI.(nullSecretUI); !ok {
		t.Errorf("secretUI %v is not a nullSecretUI", secretUI)
	}
}
예제 #2
0
파일: rekey_test.go 프로젝트: qbit/client
// A rekey is needed, but the user closes the rekey status window.
func TestRekeyNeededUserClose(t *testing.T) {
	tc := libkb.SetupTest(t, "gregor", 1)
	defer tc.Cleanup()

	rkeyui := &fakeRekeyUI{}
	rkeyui.notifyRefresh = make(chan bool, 10)
	router := fakeUIRouter{
		rekeyUI: rkeyui,
	}
	tc.G.SetUIRouter(&router)

	clock := clockwork.NewFakeClock()
	tc.G.SetClock(clock)

	gUID, h, rekeyHandler := rekeySetup(tc)

	rekeyBroadcast(tc, gUID, h, problemSet)

	select {
	case <-rekeyHandler.notifyStart:
	case <-time.After(20 * time.Second):
		t.Fatal("timeout waiting for rekeyHandler.notifyStart")
	}

	// since this is testing that the user closes a rekey status window,
	// wait for the refresh call:
	select {
	case <-rkeyui.notifyRefresh:
	case <-time.After(20 * time.Second):
		t.Fatal("timeout waiting for rekeyui.notifyRefresh")
	}

	// now call finish
	outcome, err := h.RekeyStatusFinish(context.Background(), rkeyui.sessionID)
	if err != nil {
		t.Fatal(err)
	}
	if outcome != keybase1.Outcome_IGNORED {
		t.Fatalf("RekeyStatusFinish outcome: %v, expected %v", outcome, keybase1.Outcome_IGNORED)
	}

	clock.Advance(3 * time.Second)

	select {
	case <-rekeyHandler.notifyComplete:
	case <-time.After(20 * time.Second):
		t.Fatal("timeout waiting for rekeyHandler.notifyComplete")
	}

	// there should be one call to refresh to bring the window up, but then the RekeyStatusFinish call above
	// should close the window and stop the loop.
	if len(rkeyui.refreshArgs) != 1 {
		t.Fatalf("rkeyui refresh calls: %d, expected 1", len(rkeyui.refreshArgs))
	}

	if len(rkeyui.refreshArgs[0].ProblemSetDevices.ProblemSet.Tlfs) != 1 {
		t.Errorf("first refresh call, tlf count = %d, expected 1", len(rkeyui.refreshArgs[0].ProblemSetDevices.ProblemSet.Tlfs))
	}
}
예제 #3
0
func setupTest(t *testing.T, nm string) *libkb.TestContext {
	tc := libkb.SetupTest(t, nm)
	tc.SetRuntimeDir(filepath.Join(tc.Tp.Home, "run"))
	if err := tc.G.ConfigureSocketInfo(); err != nil {
		t.Fatal(err)
	}
	return &tc
}
예제 #4
0
파일: rekey_test.go 프로젝트: qbit/client
func TestRekeyNeededMessageNoScores(t *testing.T) {
	t.Skip()
	tc := libkb.SetupTest(t, "gregor", 1)
	defer tc.Cleanup()

	gUID, h, _ := rekeySetup(tc)

	// Test that a broadcast with an empty body works.
	rekeyBroadcast(tc, gUID, h, `{}`)
}
예제 #5
0
파일: common_test.go 프로젝트: qbit/client
func SetupEngineTest(tb testing.TB, name string) libkb.TestContext {
	tc := libkb.SetupTest(tb, name, 2)
	tc.G.NewTriplesec = func(passphrase []byte, salt []byte) (libkb.Triplesec, error) {
		warner := func() { tc.G.Log.Warning("Installing insecure Triplesec with weak stretch parameters") }
		isProduction := func() bool {
			return tc.G.Env.GetRunMode() == libkb.ProductionRunMode
		}
		return insecureTriplesec.NewCipher(passphrase, salt, warner, isProduction)
	}
	return tc
}
예제 #6
0
func TestAPIServerPostJSON(t *testing.T) {

	tc := libkb.SetupTest(t, "apiserver", 2)
	defer tc.Cleanup()
	tc.G.SetService()

	_, err := kbtest.CreateAndSignupFakeUser("apivr", tc.G)
	if err != nil {
		t.Fatal(err)
	}

	jsonPayload := []keybase1.StringKVPair{
		{Key: "sigs", Value: "[]"},
	}

	arg := keybase1.PostJSONArg{
		Endpoint:    "key/multi",
		JSONPayload: jsonPayload,
	}

	handler := NewAPIServerHandler(nil, tc.G)
	res, err := handler.doPostJSON(arg)
	if err != nil {
		t.Fatal(err)
	}

	jw, err := jsonw.Unmarshal([]byte(res.Body))
	if err != nil {
		t.Fatal(err)
	}

	namew := jw.AtKey("status").AtKey("name")
	name, err := namew.GetString()
	if err != nil {
		t.Fatal(err)
	}

	if name != "OK" {
		t.Fatalf("wrong name returned: %s != %s", name, "OK")
	}
}
예제 #7
0
func TestAPIServerGet(t *testing.T) {
	tc := libkb.SetupTest(t, "apiserver", 2)
	defer tc.Cleanup()
	tc.G.SetService()

	_, err := kbtest.CreateAndSignupFakeUser("apivr", tc.G)
	if err != nil {
		t.Fatal(err)
	}

	harg := []keybase1.StringKVPair{
		{Key: "username", Value: "t_alice"},
		{Key: "fields", Value: "basics"},
	}

	arg := keybase1.GetArg{
		Endpoint: "user/lookup",
		Args:     harg,
	}

	handler := NewAPIServerHandler(nil, tc.G)
	res, err := handler.doGet(arg)
	if err != nil {
		t.Fatal(err)
	}

	jw, err := jsonw.Unmarshal([]byte(res.Body))
	if err != nil {
		t.Fatal(err)
	}

	usernamew := jw.AtKey("them").AtKey("basics").AtKey("username")
	username, err := usernamew.GetString()
	if err != nil {
		t.Fatal(err)
	}

	if username != "t_alice" {
		t.Fatalf("wrong username returned: %s != %s", username, "t_alice")
	}
}
예제 #8
0
파일: common_test.go 프로젝트: moul/client
func SetupEngineTest(tb testing.TB, name string) libkb.TestContext {
	tc := libkb.SetupTest(tb, name)
	return tc
}
예제 #9
0
파일: rekey_test.go 프로젝트: qbit/client
func TestRekeyNeededMessageWithScores(t *testing.T) {
	tc := libkb.SetupTest(t, "gregor", 1)
	defer tc.Cleanup()

	rkeyui := &fakeRekeyUI{}
	router := fakeUIRouter{
		rekeyUI: rkeyui,
	}
	tc.G.SetUIRouter(&router)

	clock := clockwork.NewFakeClock()
	tc.G.SetClock(clock)

	gUID, h, rekeyHandler := rekeySetup(tc)

	rekeyBroadcast(tc, gUID, h, problemSet)

	select {
	case <-rekeyHandler.notifyStart:
	case <-time.After(20 * time.Second):
		t.Fatal("timeout waiting for rekeyHandler.notifyStart")
	}

	done := make(chan struct{})
	defer close(done)
	go func() {
		for {
			select {
			case <-done:
				return
			default:
				clock.Advance(1 * time.Second)
			}
		}
	}()

	select {
	case <-rekeyHandler.notifyComplete:
	case <-time.After(20 * time.Second):
		t.Fatal("timeout waiting for rekeyHandler.notifyComplete")
	}

	// Test that refresh was called twice.
	if len(rkeyui.refreshArgs) != 2 {
		t.Fatalf("rkeyui refresh calls: %d, expected 2", len(rkeyui.refreshArgs))
	}

	// the first call should contain a TLF
	if len(rkeyui.refreshArgs[0].ProblemSetDevices.ProblemSet.Tlfs) != 1 {
		t.Errorf("first refresh call, tlf count = %d, expected 1", len(rkeyui.refreshArgs[0].ProblemSetDevices.ProblemSet.Tlfs))
	}
	// the second call should have updated the scores, and have no more TLFs in it.
	if len(rkeyui.refreshArgs[1].ProblemSetDevices.ProblemSet.Tlfs) != 0 {
		t.Errorf("second/final refresh call, tlf count = %d, expected 0", len(rkeyui.refreshArgs[1].ProblemSetDevices.ProblemSet.Tlfs))
	}

	// check the devices field
	if len(rkeyui.refreshArgs[0].ProblemSetDevices.Devices) != 1 {
		t.Fatalf("num devices: %d, expected 1", len(rkeyui.refreshArgs[0].ProblemSetDevices.Devices))
	}
	d := rkeyui.refreshArgs[0].ProblemSetDevices.Devices[0]
	if d.DeviceID != "640ee4f517c2a0ff190456952df26e18" {
		t.Errorf("device id: %v, expected 640ee4f517c2a0ff190456952df26e18", d.DeviceID)
	}
	if d.VerifyKey != "01206f31b54690a95a1a60a0d8861c8ec27c322b49a93b475a631ee6a676018bfd140a" {
		t.Errorf("device verify key: %v, expected 01206f31b54690a95a1a60a0d8861c8ec27c322b49a93b475a631ee6a676018bfd140a", d.VerifyKey)
	}
}
예제 #10
0
파일: rekey_test.go 프로젝트: qbit/client
// After user cancels rekey harass window, it should be spawned 24h later.
func TestRekeyReharass(t *testing.T) {
	tc := libkb.SetupTest(t, "gregor", 1)
	defer tc.Cleanup()

	rkeyui := &fakeRekeyUI{}
	rkeyui.notifyRefresh = make(chan bool, 10)
	router := fakeUIRouter{
		rekeyUI: rkeyui,
	}
	tc.G.SetUIRouter(&router)

	clock := clockwork.NewFakeClock()
	tc.G.SetClock(clock)

	gUID, gregorHandler, rekeyUIHandler := rekeySetup(tc)

	// need a RekeyHandler for this test too (it has the rekey reharass loop in it)
	// creating it here to fake the time.Ticker
	rekeyHandler := &RekeyHandler{
		Contextified: libkb.NewContextified(tc.G),
		gregor:       gregorHandler,
		scorer:       fakeScoreProblemFoldersFull,
	}
	ticker := make(chan time.Time)
	go rekeyHandler.recheckRekeyStatusTicker(ticker)

	rekeyBroadcast(tc, gUID, gregorHandler, problemSet)

	// 1. start
	select {
	case <-rekeyUIHandler.notifyStart:
	case <-time.After(20 * time.Second):
		t.Fatal("timeout waiting for rekeyUIHandler.notifyStart")
	}

	// 2. refresh called on ui
	select {
	case <-rkeyui.notifyRefresh:
	case <-time.After(20 * time.Second):
		t.Fatal("timeout waiting for rekeyui.notifyRefresh")
	}

	// 3. user cancels rekey window
	outcome, err := rekeyHandler.RekeyStatusFinish(context.Background(), rkeyui.sessionID)
	if err != nil {
		t.Fatal(err)
	}
	if outcome != keybase1.Outcome_IGNORED {
		t.Fatalf("RekeyStatusFinish outcome: %v, expected %v", outcome, keybase1.Outcome_IGNORED)
	}

	clock.Advance(3 * time.Second)

	// 4. wait for it to finish
	select {
	case <-rekeyUIHandler.notifyComplete:
	case <-time.After(20 * time.Second):
		t.Fatal("timeout waiting for rekeyHandler.notifyComplete")
	}

	// There should only be one call to refresh to bring the window up
	// The RekeyStatusFinish call above should close the window and stop the loop.
	if len(rkeyui.refreshArgs) != 1 {
		t.Fatalf("rkeyui refresh calls: %d, expected 1", len(rkeyui.refreshArgs))
	}

	// A recheck deadline should be set
	if rekeyHandler.isRecheckDeadlineZero() {
		t.Fatalf("rekeyHandler recheckDeadline is zero, it should be set to a time in the future")
	}

	// 5. fast-forward 25h
	clock.Advance(25 * time.Hour)
	ticker <- clock.Now()

	// 6. rekey updater loop should start up again
	select {
	case <-rekeyUIHandler.notifyStart:
	case <-time.After(20 * time.Second):
		t.Fatal("timeout waiting for rekeyUIHandler.notifyStart")
	}

	// 7. refresh called on ui
	select {
	case <-rkeyui.notifyRefresh:
	case <-time.After(20 * time.Second):
		t.Fatal("timeout waiting for rekeyui.notifyRefresh")
	}

	// make sure refresh was called again
	if len(rkeyui.refreshArgs) != 2 {
		t.Fatalf("rkeyui refresh calls: %d, expected 2", len(rkeyui.refreshArgs))
	}
}
예제 #11
0
파일: common_test.go 프로젝트: qbit/client
func SetupEngineTestRealTriplesec(tb testing.TB, name string) libkb.TestContext {
	tc := libkb.SetupTest(tb, name, 2)
	tc.G.NewTriplesec = libkb.NewSecureTriplesec
	return tc
}