-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSecureStoreConfigurationExtensionsTests.cs
More file actions
85 lines (74 loc) · 3 KB
/
SecureStoreConfigurationExtensionsTests.cs
File metadata and controls
85 lines (74 loc) · 3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
namespace SecureStore.Contrib.Configuration.Tests
{
using System;
using System.IO;
using Microsoft.Extensions.Configuration;
using Xunit;
public class SecureStoreConfigurationExtensionsTests
{
[Fact]
public void AddSecureStoreFile_ThrowsIfBuilderIsNull()
{
// Arrange
var path = "does-not-exist.json";
var key = "password";
// Act and Assert
var ex = Assert.Throws<ArgumentNullException>(() =>
SecureStoreConfigurationExtensions.AddSecureStoreFile(null, path, key, KeyType.Password).Build());
Assert.StartsWith("builder", ex.ParamName);
}
[Theory]
[InlineData(null)]
[InlineData("")]
public void AddSecureStoreFile_ThrowsIfFilePathIsNullOrEmpty(string path)
{
// Arrange
var configurationBuilder = new ConfigurationBuilder();
var key = "password";
// Act and Assert
var ex = Assert.Throws<ArgumentException>(() =>
configurationBuilder.AddSecureStoreFile(path, key, KeyType.Password));
Assert.Equal("path", ex.ParamName);
Assert.StartsWith("File path must be a non-empty string.", ex.Message);
}
[Theory]
[InlineData(null)]
[InlineData("")]
public void AddSecureStoreFile_ThrowsIfKeyIsNullOrEmpty(string key)
{
// Arrange
var configurationBuilder = new ConfigurationBuilder();
var path = "does-not-exist.json";
// Act and Assert
var ex = Assert.Throws<ArgumentException>(() =>
configurationBuilder.AddSecureStoreFile(path, key, KeyType.Password));
Assert.Equal("key", ex.ParamName);
Assert.StartsWith("File key/path must be a non-empty string.", ex.Message);
}
[Fact]
public void AddSecureStoreFile_ThrowsIfFileDoesNotExistAtPath()
{
// Arrange
var path = "does-not-exist.json";
var key = "password";
// Act and Assert
var ex = Assert.Throws<FileNotFoundException>(() =>
new ConfigurationBuilder().AddSecureStoreFile(path, key, KeyType.Password).Build());
Assert.StartsWith($"The configuration file '{path}' was not found and is not optional.", ex.Message);
}
[Fact]
public void AddSecureStoreFile_ThrowsIfFileDoesNotExistAtKey()
{
// Arrange
var path = Path.GetTempFileName();
TestSecureStoreHelpers.CreateTestStore(path);
var keyPath = "does-not-exist.json";
// Act and Assert
var ex = Assert.Throws<FileNotFoundException>(() =>
new ConfigurationBuilder().AddSecureStoreFile(path, keyPath, KeyType.File).Build());
Assert.StartsWith($"The configuration key file '{keyPath}' was not found", ex.Message);
// Cleanup
File.Delete(path);
}
}
}