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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
elixxir
client
Commits
c6df37cb
Commit
c6df37cb
authored
3 years ago
by
Josh Brooks
Browse files
Options
Downloads
Patches
Plain Diff
Implement serviceList tests
parent
7f0795c3
No related branches found
No related tags found
3 merge requests
!510
Release
,
!223
Implement serviceList tests
,
!207
WIP: Client Restructure
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
e2e/ratchet/serviceList_test.go
+123
-0
123 additions, 0 deletions
e2e/ratchet/serviceList_test.go
e2e/ratchet/utils_test.go
+48
-9
48 additions, 9 deletions
e2e/ratchet/utils_test.go
ud/utils_test.go
+0
-7
0 additions, 7 deletions
ud/utils_test.go
with
171 additions
and
16 deletions
e2e/ratchet/serviceList_test.go
0 → 100644
+
123
−
0
View file @
c6df37cb
////////////////////////////////////////////////////////////////////////////////
// Copyright © 2020 xx network SEZC //
// //
// Use of this source code is governed by a license that can be found in the //
// LICENSE file //
////////////////////////////////////////////////////////////////////////////////
package
ratchet
import
(
"reflect"
"testing"
)
// Happy path
func
TestRatchet_AddService
(
t
*
testing
.
T
)
{
// Initialize ratchet
r
,
_
,
err
:=
makeTestRatchet
()
if
err
!=
nil
{
t
.
Fatalf
(
"Setup error: %v"
,
err
)
}
// Add service to ratchet
tag
:=
"youreIt"
procName
:=
"mario"
expected
:=
&
mockProcessor
{
name
:
procName
}
err
=
r
.
AddService
(
tag
,
expected
)
if
err
!=
nil
{
t
.
Fatalf
(
"AddService error: %+v"
,
err
)
}
// Ensure service exists within the map
received
,
ok
:=
r
.
services
[
tag
]
if
!
ok
{
t
.
Fatalf
(
"Could not find processor in map"
)
}
// Ensure the entry in the map is what was added
if
!
reflect
.
DeepEqual
(
received
,
expected
)
{
t
.
Fatalf
(
"Did not receive expected service."
+
"
\n
Expected: %+v"
+
"
\n
Received: %+v"
,
expected
,
received
)
}
}
// Error path: attempting to add to an already existing tag
// should result in an error
func
TestRatchet_AddService_DuplicateAddErr
(
t
*
testing
.
T
)
{
// Initialize ratchet
r
,
_
,
err
:=
makeTestRatchet
()
if
err
!=
nil
{
t
.
Fatalf
(
"Setup error: %v"
,
err
)
}
// Add a mock service
tag
:=
"youreIt"
err
=
r
.
AddService
(
tag
,
&
mockProcessor
{})
if
err
!=
nil
{
t
.
Fatalf
(
"AddService error: %+v"
,
err
)
}
// Add a mock service with the same tag should result in an error
err
=
r
.
AddService
(
tag
,
&
mockProcessor
{})
if
err
==
nil
{
t
.
Fatalf
(
"Expected error: "
+
"Should not be able to add more than one service"
)
}
}
// Happy path
func
TestRatchet_RemoveService
(
t
*
testing
.
T
)
{
// Initialize ratchet
r
,
_
,
err
:=
makeTestRatchet
()
if
err
!=
nil
{
t
.
Fatalf
(
"Setup error: %v"
,
err
)
}
// Add a mock service
tag
:=
"youreIt"
err
=
r
.
AddService
(
tag
,
&
mockProcessor
{})
if
err
!=
nil
{
t
.
Fatalf
(
"AddService error: %+v"
,
err
)
}
// Remove the service
err
=
r
.
RemoveService
(
tag
)
if
err
!=
nil
{
t
.
Fatalf
(
"RemoveService error: %+v"
,
err
)
}
// Ensure service does not exist within the map
_
,
ok
:=
r
.
services
[
tag
]
if
ok
{
t
.
Fatalf
(
"Entry with tag %s should not be in map"
,
tag
)
}
}
// Error path: removing a service that does not exist
func
TestRatchet_RemoveService_DoesNotExistError
(
t
*
testing
.
T
)
{
// Initialize ratchet
r
,
_
,
err
:=
makeTestRatchet
()
if
err
!=
nil
{
t
.
Fatalf
(
"Setup error: %v"
,
err
)
}
// Remove the service that does not exist
tag
:=
"youreIt"
err
=
r
.
RemoveService
(
tag
)
if
err
==
nil
{
t
.
Fatalf
(
"Expected error: RemoveService should return an error when "
+
"trying to move a service that was not added"
)
}
// Ensure service does not exist within the map
_
,
ok
:=
r
.
services
[
tag
]
if
ok
{
t
.
Fatalf
(
"Entry with tag %s should not be in map"
,
tag
)
}
}
This diff is collapsed.
Click to expand it.
e2e/ratchet/utils_test.go
+
48
−
9
View file @
c6df37cb
////////////////////////////////////////////////////////////////////////////////
// Copyright © 2020 xx network SEZC //
// //
// Use of this source code is governed by a license that can be found in the //
// LICENSE file //
////////////////////////////////////////////////////////////////////////////////
package
ratchet
import
(
"gitlab.com/elixxir/client/cmix/identity/receptionID"
"gitlab.com/elixxir/client/cmix/rounds"
"gitlab.com/elixxir/primitives/format"
"io"
"reflect"
"testing"
...
...
@@ -20,6 +30,7 @@ import (
"gitlab.com/xx_network/primitives/id"
)
// Constructor for a mock ratchet
func
makeTestRatchet
()
(
*
Ratchet
,
*
versioned
.
KV
,
error
)
{
grp
:=
cyclic
.
NewGroup
(
large
.
NewInt
(
107
),
large
.
NewInt
(
2
))
privKey
:=
grp
.
NewInt
(
57
)
...
...
@@ -27,7 +38,8 @@ func makeTestRatchet() (*Ratchet, *versioned.KV, error) {
rng
:=
fastRNG
.
NewStreamGenerator
(
12
,
3
,
csprng
.
NewSystemRNG
)
err
:=
New
(
kv
,
&
id
.
ID
{},
privKey
,
grp
)
if
err
!=
nil
{
return
nil
,
nil
,
errors
.
Errorf
(
"NewStore() produced an error: %v"
,
err
)
return
nil
,
nil
,
errors
.
Errorf
(
"NewStore() produced an error: %v"
,
err
)
}
cyHanlder
:=
mockCyHandler
{}
...
...
@@ -42,6 +54,7 @@ func makeTestRatchet() (*Ratchet, *versioned.KV, error) {
return
r
,
kv
,
err
}
// Helper function which compares 2 partner.Manager's.
func
managersEqual
(
expected
,
received
partner
.
Manager
,
t
*
testing
.
T
)
bool
{
equal
:=
true
if
!
reflect
.
DeepEqual
(
expected
.
PartnerId
(),
received
.
PartnerId
())
{
...
...
@@ -54,7 +67,8 @@ func managersEqual(expected, received partner.Manager, t *testing.T) bool {
if
!
reflect
.
DeepEqual
(
expected
.
ConnectionFingerprint
(),
received
.
ConnectionFingerprint
())
{
t
.
Errorf
(
"Did not Receive expected Manager.Receive."
+
"
\n\t
expected: %+v
\n\t
received: %+v"
,
expected
.
ConnectionFingerprint
(),
received
.
ConnectionFingerprint
())
expected
.
ConnectionFingerprint
(),
received
.
ConnectionFingerprint
())
equal
=
false
}
if
!
reflect
.
DeepEqual
(
expected
.
MyId
(),
received
.
MyId
())
{
...
...
@@ -64,24 +78,30 @@ func managersEqual(expected, received partner.Manager, t *testing.T) bool {
equal
=
false
}
if
!
reflect
.
DeepEqual
(
expected
.
MyRootPrivateKey
(),
received
.
MyRootPrivateKey
())
{
if
!
reflect
.
DeepEqual
(
expected
.
MyRootPrivateKey
(),
received
.
MyRootPrivateKey
())
{
t
.
Errorf
(
"Did not Receive expected Manager.MyPrivateKey."
+
"
\n\t
expected: %+v
\n\t
received: %+v"
,
expected
.
MyRootPrivateKey
(),
received
.
MyRootPrivateKey
())
equal
=
false
}
if
!
reflect
.
DeepEqual
(
expected
.
SendRelationshipFingerprint
(),
received
.
SendRelationshipFingerprint
())
{
t
.
Errorf
(
"Did not Receive expected Manager.SendRelationshipFingerprint."
+
if
!
reflect
.
DeepEqual
(
expected
.
SendRelationshipFingerprint
(),
received
.
SendRelationshipFingerprint
())
{
t
.
Errorf
(
"Did not Receive expected Manager."
+
"SendRelationshipFingerprint."
+
"
\n\t
expected: %+v
\n\t
received: %+v"
,
expected
.
SendRelationshipFingerprint
(),
received
.
SendRelationshipFingerprint
())
expected
.
SendRelationshipFingerprint
(),
received
.
SendRelationshipFingerprint
())
equal
=
false
}
return
equal
}
func
genSidhKeys
(
rng
io
.
Reader
,
variant
sidh
.
KeyVariant
)
(
*
sidh
.
PrivateKey
,
*
sidh
.
PublicKey
)
{
// Helper function for generating sidh keys.
func
genSidhKeys
(
rng
io
.
Reader
,
variant
sidh
.
KeyVariant
)
(
*
sidh
.
PrivateKey
,
*
sidh
.
PublicKey
)
{
sidHPrivKey
:=
util
.
NewSIDHPrivateKey
(
variant
)
sidHPubKey
:=
util
.
NewSIDHPublicKey
(
variant
)
...
...
@@ -93,6 +113,7 @@ func genSidhKeys(rng io.Reader, variant sidh.KeyVariant) (*sidh.PrivateKey, *sid
return
sidHPrivKey
,
sidHPubKey
}
// Implements a mock session.CypherHandler.
type
mockCyHandler
struct
{}
func
(
m
mockCyHandler
)
AddKey
(
k
session
.
Cypher
)
{
...
...
@@ -103,12 +124,30 @@ func (m mockCyHandler) DeleteKey(k session.Cypher) {
return
}
// Implements a mock Services interface.
type
mockServices
struct
{}
func
(
s
mockServices
)
AddService
(
AddService
*
id
.
ID
,
newService
message
.
Service
,
func
(
s
mockServices
)
AddService
(
AddService
*
id
.
ID
,
newService
message
.
Service
,
response
message
.
Processor
)
{
}
func
(
s
mockServices
)
DeleteService
(
clientID
*
id
.
ID
,
toDelete
message
.
Service
,
func
(
s
mockServices
)
DeleteService
(
clientID
*
id
.
ID
,
toDelete
message
.
Service
,
processor
message
.
Processor
)
{
}
// Implements a message.Processor interface.
type
mockProcessor
struct
{
name
string
}
func
(
m
*
mockProcessor
)
Process
(
message
format
.
Message
,
receptionID
receptionID
.
EphemeralIdentity
,
round
rounds
.
Round
)
{
}
func
(
m
*
mockProcessor
)
String
()
string
{
return
m
.
name
}
This diff is collapsed.
Click to expand it.
ud/utils_test.go
+
0
−
7
View file @
c6df37cb
...
...
@@ -5,13 +5,6 @@
// LICENSE file //
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Copyright © 2020 xx network SEZC //
// //
// Use of this source code is governed by a license that can be found in the //
// LICENSE file //
////////////////////////////////////////////////////////////////////////////////
package
ud
import
(
...
...
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