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
436af9cb
Commit
436af9cb
authored
Aug 28, 2020
by
Niamh Nikali
Browse files
Options
Downloads
Patches
Plain Diff
Add tests for all session methods
parent
81ceff59
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
storage/e2e/session.go
+3
-3
3 additions, 3 deletions
storage/e2e/session.go
storage/e2e/session_test.go
+143
-1
143 additions, 1 deletion
storage/e2e/session_test.go
storage/e2e/status.go
+4
-0
4 additions, 0 deletions
storage/e2e/status.go
with
150 additions
and
4 deletions
storage/e2e/session.go
+
3
−
3
View file @
436af9cb
...
@@ -262,11 +262,11 @@ func (s *Session) PopReKey() (*Key, error) {
...
@@ -262,11 +262,11 @@ func (s *Session) PopReKey() (*Key, error) {
// returns the state of the session, which denotes if the Session is active,
// returns the state of the session, which denotes if the Session is active,
// functional but in need of a rekey, empty of send key, or empty of rekeys
// functional but in need of a rekey, empty of send key, or empty of rekeys
func
(
s
*
Session
)
Status
()
Status
{
func
(
s
*
Session
)
Status
()
Status
{
if
s
.
keyState
.
numkeys
-
s
.
keyState
.
numAvailable
<=
uint32
(
s
.
params
.
NumRekeys
)
{
if
s
.
keyState
.
GetNumAvailable
()
==
0
{
return
RekeyEmpty
return
RekeyEmpty
}
else
if
s
.
keyState
.
GetNum
Keys
()
=
=
0
{
}
else
if
s
.
keyState
.
GetNum
Available
()
<
=
uint32
(
s
.
params
.
NumRekeys
)
{
return
Empty
return
Empty
}
else
if
s
.
keyState
.
GetNumKeys
()
>=
s
.
ttl
{
}
else
if
s
.
keyState
.
GetNumAvailable
()
<=
s
.
keyState
.
GetNumKeys
()
-
s
.
ttl
{
return
RekeyNeeded
return
RekeyNeeded
}
else
{
}
else
{
return
Active
return
Active
...
...
This diff is collapsed.
Click to expand it.
storage/e2e/session_test.go
+
143
−
1
View file @
436af9cb
...
@@ -331,7 +331,149 @@ func TestSession_PopKey_Error(t *testing.T) {
...
@@ -331,7 +331,149 @@ func TestSession_PopKey_Error(t *testing.T) {
t
.
Log
(
err
)
t
.
Log
(
err
)
}
}
// PopRekey
// PopRekey should return the next key
// There's no boundary, except for the number of keynums in the state vector
func
TestSession_PopReKey
(
t
*
testing
.
T
)
{
s
,
_
:=
makeTestSession
(
t
)
key
,
err
:=
s
.
PopReKey
()
if
err
!=
nil
{
t
.
Fatal
(
"PopKey should have returned an error"
)
}
if
key
==
nil
{
t
.
Error
(
"Key should be non-nil"
)
}
if
key
.
session
!=
s
{
t
.
Error
(
"Key should record it belongs to this session"
)
}
// PopReKey should return the first available key
if
key
.
keyNum
!=
0
{
t
.
Error
(
"First key popped should have keynum 0"
)
}
}
// PopRekey should not return the next key if there are no more keys available
// in the state vector
func
TestSession_PopReKey_Err
(
t
*
testing
.
T
)
{
s
,
ctx
:=
makeTestSession
(
t
)
// Construct a specific state vector that will quickly run out of keys
var
err
error
s
.
keyState
,
err
=
newStateVector
(
ctx
,
makeStateVectorKey
(
keyEKVPrefix
,
s
.
GetID
()),
0
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
_
,
err
=
s
.
PopReKey
()
if
err
==
nil
{
t
.
Fatal
(
"PopReKey should have returned an error"
)
}
}
// Simple test that shows the base key can get got
func
TestSession_GetBaseKey
(
t
*
testing
.
T
)
{
s
,
_
:=
makeTestSession
(
t
)
baseKey
:=
s
.
GetBaseKey
()
if
baseKey
.
Cmp
(
s
.
baseKey
)
!=
0
{
t
.
Errorf
(
"expected %v, got %v"
,
baseKey
.
Text
(
16
),
s
.
baseKey
.
Text
(
16
))
}
}
// Smoke test for GetID
func
TestSession_GetID
(
t
*
testing
.
T
)
{
s
,
_
:=
makeTestSession
(
t
)
id
:=
s
.
GetID
()
if
len
(
id
.
Bytes
())
==
0
{
t
.
Error
(
"Zero length for session ID!"
)
}
}
// Smoke test for GetPartnerPubKey
func
TestSession_GetPartnerPubKey
(
t
*
testing
.
T
)
{
s
,
_
:=
makeTestSession
(
t
)
partnerPubKey
:=
s
.
GetPartnerPubKey
()
if
partnerPubKey
.
Cmp
(
s
.
partnerPubKey
)
!=
0
{
t
.
Errorf
(
"expected %v, got %v"
,
partnerPubKey
.
Text
(
16
),
s
.
partnerPubKey
.
Text
(
16
))
}
}
// Smoke test for GetMyPrivKey
func
TestSession_GetMyPrivKey
(
t
*
testing
.
T
)
{
s
,
_
:=
makeTestSession
(
t
)
myPrivKey
:=
s
.
GetMyPrivKey
()
if
myPrivKey
.
Cmp
(
s
.
myPrivKey
)
!=
0
{
t
.
Errorf
(
"expected %v, got %v"
,
myPrivKey
.
Text
(
16
),
s
.
myPrivKey
.
Text
(
16
))
}
}
// Shows that IsConfirmed returns whether the session is confirmed
func
TestSession_IsConfirmed
(
t
*
testing
.
T
)
{
s
,
_
:=
makeTestSession
(
t
)
s
.
confirmed
=
false
if
s
.
IsConfirmed
()
{
t
.
Error
(
"s was confirmed when it shouldn't have been"
)
}
s
.
confirmed
=
true
if
!
s
.
IsConfirmed
()
{
t
.
Error
(
"s wasn't confirmed when it should have been"
)
}
}
// IsReKeyNeeded only returns true once, when the number of keys available is
// equal to the TTL. If it returned true after the TTL, it could result in
// additional, unnecessary rekeys.
func
TestSession_IsReKeyNeeded
(
t
*
testing
.
T
)
{
s
,
_
:=
makeTestSession
(
t
)
s
.
keyState
.
numAvailable
=
s
.
ttl
if
!
s
.
IsReKeyNeeded
()
{
t
.
Error
(
"Rekey should be needed if the number available is the TTL"
)
}
s
.
keyState
.
numAvailable
=
s
.
ttl
+
1
if
s
.
IsReKeyNeeded
()
{
t
.
Error
(
"Rekey shouldn't be needed in this case"
)
}
s
.
keyState
.
numAvailable
=
s
.
ttl
-
1
if
s
.
IsReKeyNeeded
()
{
t
.
Error
(
"Rekey shouldn't be needed in this case"
)
}
}
// Shows that Status can result in all possible statuses
func
TestSession_Status
(
t
*
testing
.
T
)
{
s
,
ctx
:=
makeTestSession
(
t
)
var
err
error
s
.
keyState
,
err
=
newStateVector
(
ctx
,
makeStateVectorKey
(
keyEKVPrefix
,
s
.
GetID
()),
500
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
s
.
keyState
.
numAvailable
=
0
if
s
.
Status
()
!=
RekeyEmpty
{
t
.
Error
(
"status should have been rekey empty with no keys left"
)
}
s
.
keyState
.
numAvailable
=
1
if
s
.
Status
()
!=
Empty
{
t
.
Error
(
"Status should have been empty"
)
}
// Passing the ttl should result in a rekey being needed
s
.
keyState
.
numAvailable
=
s
.
keyState
.
numkeys
-
s
.
ttl
if
s
.
Status
()
!=
RekeyNeeded
{
t
.
Error
(
"Just past the ttl, rekey should be needed"
)
}
s
.
keyState
.
numAvailable
=
s
.
keyState
.
numkeys
if
s
.
Status
()
!=
Active
{
t
.
Error
(
"If all keys available, session should be active"
)
}
}
// After a Confirm call, confirmed should be true
func
TestConfirm
(
t
*
testing
.
T
)
{
s
,
_
:=
makeTestSession
(
t
)
s
.
confirmed
=
false
err
:=
s
.
confirm
()
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
!
s
.
confirmed
{
t
.
Error
(
"Should be confirmed after confirming"
)
}
}
// Make a default test session with some things populated
// Make a default test session with some things populated
func
makeTestSession
(
t
*
testing
.
T
)
(
*
Session
,
*
context
)
{
func
makeTestSession
(
t
*
testing
.
T
)
(
*
Session
,
*
context
)
{
...
...
This diff is collapsed.
Click to expand it.
storage/e2e/status.go
+
4
−
0
View file @
436af9cb
...
@@ -5,9 +5,13 @@ import "fmt"
...
@@ -5,9 +5,13 @@ import "fmt"
type
Status
uint8
type
Status
uint8
const
(
const
(
// Active sessions have keys remaining that can be used for messages
Active
Status
=
iota
Active
Status
=
iota
// RekeyNeeded sessions have keys remaining for messages, but should be rekeyed immediately
RekeyNeeded
RekeyNeeded
// Empty sessions can't be used for more messages, but can be used for rekeys
Empty
Empty
// RekeyEmpty sessions are totally empty and no longer have enough keys left for a rekey, much less messages
RekeyEmpty
RekeyEmpty
)
)
...
...
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