예제 #1
0
func TestMakeBareTlfHandleFailures(t *testing.T) {
	_, err := MakeBareTlfHandle(nil, nil, nil, nil, nil)
	assert.Equal(t, ErrNoWriters, err)

	w := []keybase1.UID{
		keybase1.MakeTestUID(4),
		keybase1.MakeTestUID(3),
	}

	r := []keybase1.UID{
		keybase1.PUBLIC_UID,
		keybase1.MakeTestUID(2),
	}

	_, err = MakeBareTlfHandle(r, nil, nil, nil, nil)
	assert.Equal(t, ErrInvalidWriter, err)

	_, err = MakeBareTlfHandle(w, r, nil, nil, nil)
	assert.Equal(t, ErrInvalidReader, err)

	ur := []keybase1.SocialAssertion{
		{
			User:    "******",
			Service: "service3",
		},
	}

	_, err = MakeBareTlfHandle(w, r[:1], nil, ur, nil)
	assert.Equal(t, ErrInvalidReader, err)
}
예제 #2
0
func TestMdcachePutPastCapacity(t *testing.T) {
	mockCtrl, config := mdCacheInit(t, 2)
	defer mdCacheShutdown(mockCtrl, config)

	id0, h0, _ := newDir(t, config, 1, true, false)
	h0.Writers = append(h0.Writers, keybase1.MakeTestUID(0))

	id1, h1, _ := newDir(t, config, 2, true, false)
	h1.Writers = append(h1.Writers, keybase1.MakeTestUID(1))

	id2, h2, _ := newDir(t, config, 3, true, false)
	h2.Writers = append(h2.Writers, keybase1.MakeTestUID(2))

	testMdcachePut(t, id0, 0, Merged, h0, config)
	testMdcachePut(t, id1, 0, Unmerged, h1, config)
	testMdcachePut(t, id2, 1, Merged, h2, config)

	// id 0 should no longer be in the cache
	// make sure we can get it successfully
	expectUsernameCalls(h0, config)
	expectedErr := NoSuchMDError{id0, 0, Merged}
	if _, err := config.MDCache().Get(id0, 0, Merged); err == nil {
		t.Errorf("No expected error on get")
	} else if err != expectedErr {
		t.Errorf("Got unexpected error on get: %v", err)
	}
}
예제 #3
0
func TestKBPKIClientHasVerifyingKey(t *testing.T) {
	c, _, localUsers := makeTestKBPKIClient(t)

	err := c.HasVerifyingKey(context.Background(), keybase1.MakeTestUID(1),
		localUsers[0].VerifyingKeys[0], time.Now())
	if err != nil {
		t.Error(err)
	}

	err = c.HasVerifyingKey(context.Background(), keybase1.MakeTestUID(1),
		VerifyingKey{}, time.Now())
	if err == nil {
		t.Error("HasVerifyingKey unexpectedly succeeded")
	}
}
예제 #4
0
// NewFolderWithIDAndWriter returns a new RootMetadataSigned for testing.
func NewFolderWithIDAndWriter(t *testing.T, id TlfID, revision MetadataRevision,
	share bool, public bool, writer keybase1.UID) (*TlfHandle, *RootMetadataSigned) {

	h := NewTlfHandle()
	if public {
		h.Readers = []keybase1.UID{keybase1.PublicUID}
	}
	h.Writers = append(h.Writers, writer)
	if share {
		h.Writers = append(h.Writers, keybase1.MakeTestUID(16))
	}

	rmd := NewRootMetadataForTest(h, id)
	rmd.Revision = revision
	rmd.LastModifyingWriter = h.Writers[0]
	rmd.LastModifyingUser = h.Writers[0]
	if !public {
		AddNewKeysOrBust(t, rmd, *NewTLFKeyBundle())
	}

	rmds := &RootMetadataSigned{}
	rmds.SigInfo = SignatureInfo{
		Version:      SigED25519,
		Signature:    []byte{42},
		VerifyingKey: MakeFakeVerifyingKeyOrBust("fake key"),
	}
	rmds.MD = *rmd
	return h, rmds
}
예제 #5
0
// Test that KBPKI forces a cache flush one time if it can't find a
// given verifying key.
func TestKBPKIClientHasVerifyingKeyStaleCache(t *testing.T) {
	ctr := NewSafeTestReporter(t)
	mockCtrl := gomock.NewController(ctr)
	config := NewConfigMock(mockCtrl, ctr)
	c := NewKBPKIClient(config)
	config.SetKBPKI(c)
	defer func() {
		config.ctr.CheckForFailures()
		mockCtrl.Finish()
	}()

	u := keybase1.MakeTestUID(1)
	key1 := MakeLocalUserVerifyingKeyOrBust("u_1")
	key2 := MakeLocalUserVerifyingKeyOrBust("u_2")
	info1 := UserInfo{
		VerifyingKeys: []VerifyingKey{key1},
	}
	config.mockKbd.EXPECT().LoadUserPlusKeys(gomock.Any(), u).
		Return(info1, nil)

	config.mockKbd.EXPECT().FlushUserFromLocalCache(gomock.Any(), u)
	info2 := UserInfo{
		VerifyingKeys: []VerifyingKey{key1, key2},
	}
	config.mockKbd.EXPECT().LoadUserPlusKeys(gomock.Any(), u).
		Return(info2, nil)

	err := c.HasVerifyingKey(context.Background(), u, key2, time.Now())
	if err != nil {
		t.Error(err)
	}
}
예제 #6
0
func TestMdcachePut(t *testing.T) {
	mockCtrl, config := mdCacheInit(t, 100)
	defer mdCacheShutdown(mockCtrl, config)

	id, h, _ := newDir(t, config, 1, true, false)
	h.Writers = append(h.Writers, keybase1.MakeTestUID(0))

	testMdcachePut(t, id, 1, Merged, h, config)
}
예제 #7
0
func makeTestKBPKIClient(t *testing.T) (
	client *KBPKIClient, currentUID keybase1.UID, users []LocalUser) {
	currentUID = keybase1.MakeTestUID(1)
	names := []libkb.NormalizedUsername{"test_name1", "test_name2"}
	users = MakeLocalUsers(names)
	daemon := NewKeybaseDaemonMemory(currentUID, users)
	config := &ConfigLocal{codec: NewCodecMsgpack(), daemon: daemon}
	setTestLogger(config, t)
	return NewKBPKIClient(config), currentUID, users
}
예제 #8
0
func TestMdcachePut(t *testing.T) {
	mockCtrl, config := mdCacheInit(t, 100)
	defer mdCacheShutdown(mockCtrl, config)

	id := FakeTlfID(1, false)
	h := parseTlfHandleOrBust(t, config, "alice", false)
	h.Writers = append(h.Writers, keybase1.MakeTestUID(0))

	testMdcachePut(t, id, 1, Merged, NullBranchID, h, config)
}
예제 #9
0
func TestKBPKIClientGetNormalizedUsername(t *testing.T) {
	c, _, _ := makeTestKBPKIClient(t)

	name, err := c.GetNormalizedUsername(context.Background(), keybase1.MakeTestUID(1))
	if err != nil {
		t.Fatal(err)
	}
	if name == libkb.NormalizedUsername("") {
		t.Fatal("empty user")
	}
}
예제 #10
0
func TestIdentify(t *testing.T) {
	nug := testNormalizedUsernameGetter{
		keybase1.MakeTestUID(1): "alice",
		keybase1.MakeTestUID(2): "bob",
		keybase1.MakeTestUID(3): "charlie",
	}

	ti := &testIdentifier{
		assertions: map[string]UserInfo{
			"alice": {
				Name: "alice",
				UID:  keybase1.MakeTestUID(1),
			},
			"bob": {
				Name: "bob",
				UID:  keybase1.MakeTestUID(2),
			},
			"charlie": {
				Name: "charlie",
				UID:  keybase1.MakeTestUID(3),
			},
		},
	}

	uids := make(map[keybase1.UID]bool, len(nug))
	uidList := make([]keybase1.UID, 0, len(nug))
	for u := range nug {
		uids[u] = true
		uidList = append(uidList, u)
	}

	err := identifyUserList(context.Background(), nug, ti, uidList, false)
	require.NoError(t, err)
	require.Equal(t, uids, ti.identifiedUids)
}
예제 #11
0
func TestKBPKIClientHasRevokedVerifyingKey(t *testing.T) {
	revokeTime := time.Now()
	c, _, localUsers := makeTestKBPKIClientWithRevokedKey(t, revokeTime)

	var revokedKey VerifyingKey
	for k := range localUsers[0].RevokedVerifyingKeys {
		revokedKey = k
		break
	}

	// Something verified before the key was revoked
	err := c.HasVerifyingKey(context.Background(), keybase1.MakeTestUID(1),
		revokedKey, revokeTime.Add(-10*time.Second))
	if err != nil {
		t.Error(err)
	}

	// Something verified after the key was revoked
	err = c.HasVerifyingKey(context.Background(), keybase1.MakeTestUID(1),
		revokedKey, revokeTime.Add(10*time.Second))
	if err == nil {
		t.Error("HasVerifyingKey unexpectedly succeeded")
	}
}
예제 #12
0
// MakeLocalUsers is a helper function to generate a list of
// LocalUsers suitable to use with KBPKILocal.
func MakeLocalUsers(users []libkb.NormalizedUsername) []LocalUser {
	localUsers := make([]LocalUser, len(users))
	for i := 0; i < len(users); i++ {
		verifyingKey := MakeLocalUserVerifyingKeyOrBust(users[i])
		cryptPublicKey := MakeLocalUserCryptPublicKeyOrBust(users[i])
		localUsers[i] = LocalUser{
			UserInfo: UserInfo{
				Name:            users[i],
				UID:             keybase1.MakeTestUID(uint32(i + 1)),
				VerifyingKeys:   []VerifyingKey{verifyingKey},
				CryptPublicKeys: []CryptPublicKey{cryptPublicKey},
			},
			CurrentCryptPublicKeyIndex: 0,
			CurrentVerifyingKeyIndex:   0,
		}
	}
	return localUsers
}
예제 #13
0
func TestKBPKIClientGetCryptPublicKeys(t *testing.T) {
	c, _, localUsers := makeTestKBPKIClient(t)

	cryptPublicKeys, err := c.GetCryptPublicKeys(context.Background(),
		keybase1.MakeTestUID(1))
	if err != nil {
		t.Fatal(err)
	}

	if len(cryptPublicKeys) != 1 {
		t.Fatalf("Expected 1 crypt public key, got %d", len(cryptPublicKeys))
	}

	kid := cryptPublicKeys[0].kid
	expectedKID := localUsers[0].CryptPublicKeys[0].kid
	if kid != expectedKID {
		t.Errorf("Expected %s, got %s", expectedKID, kid)
	}
}
예제 #14
0
func makeTestKBPKIClientWithRevokedKey(t *testing.T, revokeTime time.Time) (
	client *KBPKIClient, currentUID keybase1.UID, users []LocalUser) {
	currentUID = keybase1.MakeTestUID(1)
	names := []libkb.NormalizedUsername{"test_name1", "test_name2"}
	users = MakeLocalUsers(names)
	// Give each user a revoked key
	for i, user := range users {
		index := 99
		keySalt := keySaltForUserDevice(user.Name, index)
		newVerifyingKey := MakeLocalUserVerifyingKeyOrBust(keySalt)
		user.RevokedVerifyingKeys = map[VerifyingKey]keybase1.KeybaseTime{
			newVerifyingKey: {Unix: keybase1.ToTime(revokeTime), Chain: 100},
		}
		users[i] = user
	}
	codec := NewCodecMsgpack()
	daemon := NewKeybaseDaemonMemory(currentUID, users, codec)
	config := &ConfigLocal{codec: codec, daemon: daemon}
	setTestLogger(config, t)
	return NewKBPKIClient(config), currentUID, users
}
예제 #15
0
func TestMDOpsGetForHandleFailHandleCheck(t *testing.T) {
	mockCtrl, config, ctx := mdOpsInit(t)
	defer mdOpsShutdown(mockCtrl, config)

	// expect one call to fetch MD, and one to verify it, and fail that one
	id, h, rmds := newDir(t, config, 1, true, false)
	rmds.MD.cachedTlfHandle = NewTlfHandle()

	// add a new writer after the MD was made, to force a failure
	newWriter := keybase1.MakeTestUID(100)
	h.Writers = append(h.Writers, newWriter)
	expectUsernameCall(newWriter, config)
	config.mockMdserv.EXPECT().GetForHandle(ctx, h, Merged).Return(NullTlfID, rmds, nil)
	verifyMDForPrivate(config, rmds, id)

	if _, err := config.MDOps().GetForHandle(ctx, h); err == nil {
		t.Errorf("Got no error on bad handle check test")
	} else if _, ok := err.(MDMismatchError); !ok {
		t.Errorf("Got unexpected error on bad handle check test: %v", err)
	}
}
예제 #16
0
// NewFolderWithID returns a new RootMetadataSigned for testing.
func NewFolderWithID(t *testing.T, id TlfID, revision MetadataRevision, share bool, public bool) (
	*TlfHandle, *RootMetadataSigned) {
	return NewFolderWithIDAndWriter(t, id, revision, share, public, keybase1.MakeTestUID(15))
}
예제 #17
0
// NewFolder returns a new RootMetadataSigned for testing.
func NewFolder(t *testing.T, x byte, revision MetadataRevision, share bool, public bool) (
	TlfID, *TlfHandle, *RootMetadataSigned) {
	id := FakeTlfID(x, public)
	h, rmds := NewFolderWithIDAndWriter(t, id, revision, share, public, keybase1.MakeTestUID(15))
	return id, h, rmds
}
예제 #18
0
func TestBareTlfHandleResolveAssertions(t *testing.T) {
	w := []keybase1.UID{
		keybase1.MakeTestUID(4),
		keybase1.MakeTestUID(3),
	}

	r := []keybase1.UID{
		keybase1.MakeTestUID(5),
		keybase1.MakeTestUID(1),
	}

	uw := []keybase1.SocialAssertion{
		{
			User:    "******",
			Service: "service3",
		},
		{
			User:    "******",
			Service: "service2",
		},
		{
			User:    "******",
			Service: "service1",
		},
	}

	ur := []keybase1.SocialAssertion{
		{
			User:    "******",
			Service: "service3",
		},
		{
			User:    "******",
			Service: "service1",
		},
		{
			User:    "******",
			Service: "service1",
		},
		{
			User:    "******",
			Service: "service2",
		},
		{
			User:    "******",
			Service: "service1",
		},
		{
			User:    "******",
			Service: "service3",
		},
	}

	h, err := MakeBareTlfHandle(w, r, uw, ur, nil)
	require.NoError(t, err)

	assertions := make(map[keybase1.SocialAssertion]keybase1.UID)
	assertions[uw[0]] = keybase1.MakeTestUID(2) // new writer
	assertions[uw[2]] = keybase1.MakeTestUID(1) // reader promoted to writer
	assertions[ur[0]] = keybase1.MakeTestUID(6) // new reader
	assertions[ur[2]] = keybase1.MakeTestUID(5) // already a reader
	assertions[ur[3]] = keybase1.MakeTestUID(1) // already a writer
	assertions[ur[4]] = keybase1.MakeTestUID(9) // new reader
	assertions[ur[5]] = keybase1.MakeTestUID(9) // already a reader

	h = h.ResolveAssertions(assertions)

	require.Equal(t, []keybase1.UID{
		keybase1.MakeTestUID(1),
		keybase1.MakeTestUID(2),
		keybase1.MakeTestUID(3),
		keybase1.MakeTestUID(4),
	}, h.Writers)
	require.Equal(t, []keybase1.UID{
		keybase1.MakeTestUID(5),
		keybase1.MakeTestUID(6),
		keybase1.MakeTestUID(9),
	}, h.Readers)
	require.Equal(t, []keybase1.SocialAssertion{
		{
			User:    "******",
			Service: "service2",
		},
	}, h.UnresolvedWriters)
	require.Equal(t, []keybase1.SocialAssertion{
		{
			User:    "******",
			Service: "service1",
		},
	}, h.UnresolvedReaders)
}
예제 #19
0
func TestMakeBareTlfHandle(t *testing.T) {
	w := []keybase1.UID{
		keybase1.MakeTestUID(4),
		keybase1.MakeTestUID(3),
	}

	r := []keybase1.UID{
		keybase1.MakeTestUID(5),
		keybase1.MakeTestUID(1),
	}

	uw := []keybase1.SocialAssertion{
		{
			User:    "******",
			Service: "service3",
		},
		{
			User:    "******",
			Service: "service1",
		},
	}

	ur := []keybase1.SocialAssertion{
		{
			User:    "******",
			Service: "service3",
		},
		{
			User:    "******",
			Service: "service2",
		},
	}

	h, err := MakeBareTlfHandle(w, r, uw, ur, nil)
	require.NoError(t, err)
	require.Equal(t, []keybase1.UID{
		keybase1.MakeTestUID(3),
		keybase1.MakeTestUID(4),
	}, h.Writers)
	require.Equal(t, []keybase1.UID{
		keybase1.MakeTestUID(1),
		keybase1.MakeTestUID(5),
	}, h.Readers)
	require.Equal(t, []keybase1.SocialAssertion{
		{
			User:    "******",
			Service: "service1",
		},
		{
			User:    "******",
			Service: "service3",
		},
	}, h.UnresolvedWriters)
	require.Equal(t, []keybase1.SocialAssertion{
		{
			User:    "******",
			Service: "service2",
		},
		{
			User:    "******",
			Service: "service3",
		},
	}, h.UnresolvedReaders)
}