mirror of
https://github.com/azaion/admin.git
synced 2026-04-22 11:46:33 +00:00
Init commit
add security encryption and hashing: WIP add endpoints: register user, get and save resources add db main operations, User entity
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
using System.Text;
|
||||
using Azaion.Services;
|
||||
using FluentAssertions;
|
||||
using Xunit;
|
||||
|
||||
namespace Azaion.Test;
|
||||
|
||||
public class SecurityTest
|
||||
{
|
||||
[Fact]
|
||||
public async Task EncryptDecryptTest()
|
||||
{
|
||||
var testString = "Hello World Test dfvjkhsdbfvkljh sabdljsdafv asdv";
|
||||
var username = "user@azaion.com";
|
||||
var password = "testpw";
|
||||
var key = Security.MakeEncryptionKey(username, password);
|
||||
|
||||
await using var encryptedStream = new MemoryStream();
|
||||
await StringToStream(testString).Encrypt(encryptedStream, key);
|
||||
|
||||
await using var decryptedStream = new MemoryStream();
|
||||
await encryptedStream.Decrypt(decryptedStream, key);
|
||||
|
||||
var str = StreamToString(decryptedStream);
|
||||
str.Should().Be(testString);
|
||||
}
|
||||
|
||||
private static string StreamToString(Stream stream)
|
||||
{
|
||||
stream.Position = 0;
|
||||
using var reader = new StreamReader(stream, Encoding.UTF8);
|
||||
return reader.ReadToEnd();
|
||||
}
|
||||
|
||||
private static Stream StringToStream(string src)
|
||||
{
|
||||
var byteArray = Encoding.UTF8.GetBytes(src);
|
||||
return new MemoryStream(byteArray);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user