Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
comms
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
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
comms
Commits
8c1d700a
Commit
8c1d700a
authored
Apr 13, 2021
by
Josh Brooks
Browse files
Options
Downloads
Patches
Plain Diff
Add GetEllipticPublicKey method to instance
parent
f4e22b7d
Branches
Branches containing commit
Tags
Tags containing commit
2 merge requests
!58
Revert "Modify waiting lock"
,
!9
Release
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
network/instance.go
+19
-0
19 additions, 0 deletions
network/instance.go
network/instance_test.go
+72
-0
72 additions, 0 deletions
network/instance_test.go
with
91 additions
and
0 deletions
network/instance.go
+
19
−
0
View file @
8c1d700a
...
...
@@ -631,6 +631,25 @@ func (i *Instance) GetPermissioningCert() string {
}
// GetEllipticPublicKey gets the permissioning's elliptic public key
// from one of the NDFs
// It first checks the full ndf and returns if that has the key
// If not it checks the partial ndf and returns if it has it
// Otherwise it returns an empty string
func
(
i
*
Instance
)
GetEllipticPublicKey
()
string
{
// Check if the full ndf has the information
if
i
.
GetFullNdf
()
!=
nil
{
return
i
.
GetFullNdf
()
.
Get
()
.
Registration
.
EllipticPubKey
}
else
if
i
.
GetPartialNdf
()
!=
nil
{
// Else check if the partial ndf has the information
return
i
.
GetPartialNdf
()
.
Get
()
.
Registration
.
EllipticPubKey
}
// If neither do, return an empty string
return
""
}
// GetPermissioningId gets the permissioning ID from primitives
func
(
i
*
Instance
)
GetPermissioningId
()
*
id
.
ID
{
return
&
id
.
Permissioning
...
...
This diff is collapsed.
Click to expand it.
network/instance_test.go
+
72
−
0
View file @
8c1d700a
...
...
@@ -772,6 +772,78 @@ func TestInstance_GetPermissioningCert_NilCase(t *testing.T) {
nilNdfInstance
.
GetPermissioningCert
()
}
// Happy path: Tests GetEllipticPublicKey with the full ndf set, the partial ndf set
// and no ndf set
func
TestInstance_GetEllipticPublicKey
(
t
*
testing
.
T
)
{
// Create populated ndf (secured) and empty ndf
secured
,
_
:=
NewSecuredNdf
(
testutils
.
NDF
)
// Create an instance object, setting full to be populated
// and partial to be empty
fullNdfInstance
:=
Instance
{
full
:
secured
,
}
// Expected cert gotten from testutils.NDF
expectedKey
:=
"MqaJJ3GjFisNRM6LRedRnooi14gepMaQxyWctXVU/w4="
// GetEllipticPublicKey from the instance and compare with the expected value
receivedKey
:=
fullNdfInstance
.
GetEllipticPublicKey
()
if
expectedKey
!=
receivedKey
{
t
.
Errorf
(
"GetEllipticPublicKey did not get expected value!"
+
"
\n\t
Expected: %+v"
+
"
\n\t
Received: %+v"
,
expectedKey
,
receivedKey
)
}
// Create an instance object, setting partial to be populated
// and full to be empty
partialNdfInstance
:=
Instance
{
partial
:
secured
,
}
// GetEllipticPublicKey from the instance and compare with the expected value
receivedKey
=
partialNdfInstance
.
GetEllipticPublicKey
()
if
expectedKey
!=
receivedKey
{
t
.
Errorf
(
"GetEllipticPublicKey did not get expected value!"
+
"
\n\t
Expected: %+v"
+
"
\n\t
Received: %+v"
,
expectedKey
,
receivedKey
)
}
// Create an instance object, setting no ndf
noNdfInstance
:=
Instance
{}
// GetEllipticPublicKey, should be an empty string as no ndf's are set
receivedKey
=
noNdfInstance
.
GetEllipticPublicKey
()
if
receivedKey
!=
""
{
t
.
Errorf
(
"GetEllipticPublicKey did not get expected value!"
+
"No ndf set, cert should be an empty string. "
+
"
\n\t
Received: %+v"
,
receivedKey
)
}
}
// Error path: nil ndf is in the instance should cause a seg fault
func
TestInstance_GetEllipticPublicKey_NilCase
(
t
*
testing
.
T
)
{
// Handle expected seg fault here
defer
func
()
{
if
r
:=
recover
();
r
==
nil
{
t
.
Errorf
(
"Expected error case, should seg fault when a nil ndf is passed through"
)
}
}()
// Create a nil ndf
nilNdf
,
_
:=
NewSecuredNdf
(
nil
)
// Create an instance object with this nil ndf
nilNdfInstance
:=
Instance
{
full
:
nilNdf
,
partial
:
nilNdf
,
}
// Attempt to call getter, should seg fault
nilNdfInstance
.
GetEllipticPublicKey
()
}
// GetPermissioningId should fetch the value of id.PERMISSIONING in primitives
func
TestInstance_GetPermissioningId
(
t
*
testing
.
T
)
{
// Create an instance object,
...
...
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