-
Notifications
You must be signed in to change notification settings - Fork 151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Added] CreateUserSeed and CreateAccountSeed so these can be generated #434
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Copyright 2021-2021 The NATS Authors | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
using System; | ||
using NATS.Client; | ||
using Xunit; | ||
|
||
namespace UnitTests | ||
{ | ||
#pragma warning disable CS0618 | ||
public class TestNkeys | ||
{ | ||
[Fact] | ||
public void TestNKEYEncodeDecode() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe add seeds created by CreateUserSeed, CreateAccountSeed, etc... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. already have TestNKEYCreateUserSeed and TestNKEYCreateAccountSeed further down, will add the operator one |
||
{ | ||
byte[] a = new Byte[32]; | ||
byte[] b = Nkeys.DecodeSeed( Nkeys.EncodeSeed(20 << 3, a)); | ||
Assert.Equal(a, b); | ||
|
||
Random rnd = new Random(); | ||
rnd.NextBytes(a); | ||
b = Nkeys.DecodeSeed( Nkeys.EncodeSeed(20 << 3, a)); | ||
Assert.Equal(a, b); | ||
} | ||
|
||
[Fact] | ||
public void TestNKEYCreateUserSeed() | ||
{ | ||
string user = Nkeys.CreateUserSeed(); | ||
Assert.NotEmpty(user); | ||
Assert.NotNull(Nkeys.FromSeed(user)); | ||
} | ||
|
||
[Fact] | ||
public void TestNKEYCreateAccountSeed() | ||
{ | ||
string acc = Nkeys.CreateAccountSeed(); | ||
Assert.NotEmpty(acc); | ||
Assert.NotNull(Nkeys.FromSeed(acc)); | ||
} | ||
|
||
[Fact] | ||
public void TestNKEYCreateOperatorSeed() | ||
{ | ||
string op = Nkeys.CreateOperatorSeed(); | ||
Assert.NotEmpty(op); | ||
Assert.NotNull(Nkeys.FromSeed(op)); | ||
} | ||
} | ||
|
||
#pragma warning restore CS0618 | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps add the others for completeness in case someone want to write a utility out of this... wdyt?
eg.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will add CreateOperatorSeed. Server and Cluster are not used.