Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
client
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
elixxir
client
Commits
e3200896
Commit
e3200896
authored
Jan 28, 2022
by
Josh Brooks
Browse files
Options
Downloads
Patches
Plain Diff
Add storage tests and clean formatting
parent
0e08489b
Branches
Branches containing commit
Tags
Tags containing commit
2 merge requests
!170
Release
,
!143
added mechanisim to replay all requests. they will replay on recept if the...
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
auth/manager.go
+4
-2
4 additions, 2 deletions
auth/manager.go
storage/auth/store.go
+5
-4
5 additions, 4 deletions
storage/auth/store.go
storage/auth/store_test.go
+141
-0
141 additions, 0 deletions
storage/auth/store_test.go
with
150 additions
and
6 deletions
auth/manager.go
+
4
−
2
View file @
e3200896
...
@@ -93,6 +93,8 @@ func (m *Manager) RemoveSpecificConfirmCallback(id *id.ID) {
...
@@ -93,6 +93,8 @@ func (m *Manager) RemoveSpecificConfirmCallback(id *id.ID) {
m
.
confirmCallbacks
.
RemoveSpecific
(
id
)
m
.
confirmCallbacks
.
RemoveSpecific
(
id
)
}
}
// ReplayRequests will iterate through all pending contact requests and resend them
// to the desired contact.
func
(
m
*
Manager
)
ReplayRequests
()
{
func
(
m
*
Manager
)
ReplayRequests
()
{
cList
:=
m
.
storage
.
Auth
()
.
GetAllReceived
()
cList
:=
m
.
storage
.
Auth
()
.
GetAllReceived
()
for
i
:=
range
cList
{
for
i
:=
range
cList
{
...
...
This diff is collapsed.
Click to expand it.
storage/auth/store.go
+
5
−
4
View file @
e3200896
...
@@ -261,6 +261,7 @@ func (s *Store) AddReceived(c contact.Contact, key *sidh.PublicKey) error {
...
@@ -261,6 +261,7 @@ func (s *Store) AddReceived(c contact.Contact, key *sidh.PublicKey) error {
return
nil
return
nil
}
}
// GetAllReceived returns all pending received contact requests from storage.
func
(
s
*
Store
)
GetAllReceived
()
[]
contact
.
Contact
{
func
(
s
*
Store
)
GetAllReceived
()
[]
contact
.
Contact
{
s
.
mux
.
RLock
()
s
.
mux
.
RLock
()
defer
s
.
mux
.
RUnlock
()
defer
s
.
mux
.
RUnlock
()
...
...
This diff is collapsed.
Click to expand it.
storage/auth/store_test.go
+
141
−
0
View file @
e3200896
...
@@ -8,6 +8,7 @@
...
@@ -8,6 +8,7 @@
package
auth
package
auth
import
(
import
(
"bytes"
"github.com/cloudflare/circl/dh/sidh"
"github.com/cloudflare/circl/dh/sidh"
sidhinterface
"gitlab.com/elixxir/client/interfaces/sidh"
sidhinterface
"gitlab.com/elixxir/client/interfaces/sidh"
util
"gitlab.com/elixxir/client/storage/utility"
util
"gitlab.com/elixxir/client/storage/utility"
...
@@ -23,6 +24,7 @@ import (
...
@@ -23,6 +24,7 @@ import (
"io"
"io"
"math/rand"
"math/rand"
"reflect"
"reflect"
"sort"
"sync"
"sync"
"testing"
"testing"
)
)
...
@@ -764,6 +766,145 @@ func TestStore_Delete_RequestNotInMap(t *testing.T) {
...
@@ -764,6 +766,145 @@ func TestStore_Delete_RequestNotInMap(t *testing.T) {
}
}
}
}
// Unit test of Store.GetAllReceived.
func
TestStore_GetAllReceived
(
t
*
testing
.
T
)
{
s
,
_
,
_
:=
makeTestStore
(
t
)
numReceived
:=
10
expectContactList
:=
make
([]
contact
.
Contact
,
0
,
numReceived
)
// Add multiple received contact requests
for
i
:=
0
;
i
<
numReceived
;
i
++
{
c
:=
contact
.
Contact
{
ID
:
id
.
NewIdFromUInt
(
rand
.
Uint64
(),
id
.
User
,
t
)}
rng
:=
csprng
.
NewSystemRNG
()
_
,
sidhPubKey
:=
genSidhAKeys
(
rng
)
if
err
:=
s
.
AddReceived
(
c
,
sidhPubKey
);
err
!=
nil
{
t
.
Fatalf
(
"AddReceived() returned an error: %+v"
,
err
)
}
expectContactList
=
append
(
expectContactList
,
c
)
}
// Check that GetAllReceived returns all contacts
receivedContactList
:=
s
.
GetAllReceived
()
if
len
(
receivedContactList
)
!=
numReceived
{
t
.
Errorf
(
"GetAllReceived did not return expected amount of contacts."
+
"
\n
Expected: %d"
+
"
\n
Received: %d"
,
numReceived
,
len
(
receivedContactList
))
}
// Sort expected and received lists so that they are in the same order
// since extraction from a map does not maintain order
sort
.
Slice
(
expectContactList
,
func
(
i
,
j
int
)
bool
{
return
bytes
.
Compare
(
expectContactList
[
i
]
.
ID
.
Bytes
(),
expectContactList
[
j
]
.
ID
.
Bytes
())
==
-
1
})
sort
.
Slice
(
receivedContactList
,
func
(
i
,
j
int
)
bool
{
return
bytes
.
Compare
(
receivedContactList
[
i
]
.
ID
.
Bytes
(),
receivedContactList
[
j
]
.
ID
.
Bytes
())
==
-
1
})
// Check validity of contacts
if
!
reflect
.
DeepEqual
(
expectContactList
,
receivedContactList
)
{
t
.
Errorf
(
"GetAllReceived did not return expected contact list."
+
"
\n
Expected: %+v"
+
"
\n
Received: %+v"
,
expectContactList
,
receivedContactList
)
}
}
// Tests that Store.GetAllReceived returns an empty list when there are no
// received requests.
func
TestStore_GetAllReceived_EmptyList
(
t
*
testing
.
T
)
{
s
,
_
,
_
:=
makeTestStore
(
t
)
// Check that GetAllReceived returns all contacts
receivedContactList
:=
s
.
GetAllReceived
()
if
len
(
receivedContactList
)
!=
0
{
t
.
Errorf
(
"GetAllReceived did not return expected amount of contacts."
+
"
\n
Expected: %d"
+
"
\n
Received: %d"
,
0
,
len
(
receivedContactList
))
}
// Add Sent and Receive requests
for
i
:=
0
;
i
<
10
;
i
++
{
partnerID
:=
id
.
NewIdFromUInt
(
rand
.
Uint64
(),
id
.
User
,
t
)
rng
:=
csprng
.
NewSystemRNG
()
sidhPrivKey
,
sidhPubKey
:=
genSidhAKeys
(
rng
)
sr
:=
&
SentRequest
{
kv
:
s
.
kv
,
partner
:
partnerID
,
partnerHistoricalPubKey
:
s
.
grp
.
NewInt
(
1
),
myPrivKey
:
s
.
grp
.
NewInt
(
2
),
myPubKey
:
s
.
grp
.
NewInt
(
3
),
mySidHPrivKeyA
:
sidhPrivKey
,
mySidHPubKeyA
:
sidhPubKey
,
fingerprint
:
format
.
Fingerprint
{
5
},
}
if
err
:=
s
.
AddSent
(
sr
.
partner
,
sr
.
partnerHistoricalPubKey
,
sr
.
myPrivKey
,
sr
.
myPubKey
,
sr
.
mySidHPrivKeyA
,
sr
.
mySidHPubKeyA
,
sr
.
fingerprint
);
err
!=
nil
{
t
.
Fatalf
(
"AddSent() returned an error: %+v"
,
err
)
}
}
// Check that GetAllReceived returns all contacts
receivedContactList
=
s
.
GetAllReceived
()
if
len
(
receivedContactList
)
!=
0
{
t
.
Errorf
(
"GetAllReceived did not return expected amount of contacts. "
+
"It may be pulling from Sent Requests."
+
"
\n
Expected: %d"
+
"
\n
Received: %d"
,
0
,
len
(
receivedContactList
))
}
}
// Tests that Store.GetAllReceived returns only Sent requests when there
// are both Sent and Receive requests in Store.
func
TestStore_GetAllReceived_MixSentReceived
(
t
*
testing
.
T
)
{
s
,
_
,
_
:=
makeTestStore
(
t
)
numReceived
:=
10
// Add multiple received contact requests
for
i
:=
0
;
i
<
numReceived
;
i
++
{
// Add received request
c
:=
contact
.
Contact
{
ID
:
id
.
NewIdFromUInt
(
rand
.
Uint64
(),
id
.
User
,
t
)}
rng
:=
csprng
.
NewSystemRNG
()
_
,
sidhPubKey
:=
genSidhAKeys
(
rng
)
if
err
:=
s
.
AddReceived
(
c
,
sidhPubKey
);
err
!=
nil
{
t
.
Fatalf
(
"AddReceived() returned an error: %+v"
,
err
)
}
// Add sent request
partnerID
:=
id
.
NewIdFromUInt
(
rand
.
Uint64
(),
id
.
User
,
t
)
sidhPrivKey
,
sidhPubKey
:=
genSidhAKeys
(
rng
)
sr
:=
&
SentRequest
{
kv
:
s
.
kv
,
partner
:
partnerID
,
partnerHistoricalPubKey
:
s
.
grp
.
NewInt
(
1
),
myPrivKey
:
s
.
grp
.
NewInt
(
2
),
myPubKey
:
s
.
grp
.
NewInt
(
3
),
mySidHPrivKeyA
:
sidhPrivKey
,
mySidHPubKeyA
:
sidhPubKey
,
fingerprint
:
format
.
Fingerprint
{
5
},
}
if
err
:=
s
.
AddSent
(
sr
.
partner
,
sr
.
partnerHistoricalPubKey
,
sr
.
myPrivKey
,
sr
.
myPubKey
,
sr
.
mySidHPrivKeyA
,
sr
.
mySidHPubKeyA
,
sr
.
fingerprint
);
err
!=
nil
{
t
.
Fatalf
(
"AddSent() returned an error: %+v"
,
err
)
}
}
// Check that GetAllReceived returns all contacts
receivedContactList
:=
s
.
GetAllReceived
()
if
len
(
receivedContactList
)
!=
numReceived
{
t
.
Errorf
(
"GetAllReceived did not return expected amount of contacts. "
+
"It may be pulling from Sent Requests."
+
"
\n
Expected: %d"
+
"
\n
Received: %d"
,
numReceived
,
len
(
receivedContactList
))
}
}
func
makeTestStore
(
t
*
testing
.
T
)
(
*
Store
,
*
versioned
.
KV
,
[]
*
cyclic
.
Int
)
{
func
makeTestStore
(
t
*
testing
.
T
)
(
*
Store
,
*
versioned
.
KV
,
[]
*
cyclic
.
Int
)
{
kv
:=
versioned
.
NewKV
(
make
(
ekv
.
Memstore
))
kv
:=
versioned
.
NewKV
(
make
(
ekv
.
Memstore
))
grp
:=
cyclic
.
NewGroup
(
large
.
NewInt
(
173
),
large
.
NewInt
(
0
))
grp
:=
cyclic
.
NewGroup
(
large
.
NewInt
(
173
),
large
.
NewInt
(
0
))
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment