File tree Expand file tree Collapse file tree 2 files changed +16
-0
lines changed
SectigoCertificateManager.Tests
SectigoCertificateManager/Requests Expand file tree Collapse file tree 2 files changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,10 @@ private sealed class TestProgress : IProgress<double> {
16
16
public void Report ( double value ) => Value = value ;
17
17
}
18
18
19
+ private sealed class UnreadableStream : MemoryStream {
20
+ public override bool CanRead => false ;
21
+ }
22
+
19
23
/// <summary>Reads CSR from a stream.</summary>
20
24
[ Fact ]
21
25
public void SetCsr_FromStream_SetsProperty ( ) {
@@ -51,4 +55,12 @@ public void SetCsr_SeeksToBeginning() {
51
55
52
56
Assert . Equal ( Base64Csr , request . Csr ) ;
53
57
}
58
+
59
+ [ Fact ]
60
+ public void SetCsr_UnreadableStream_Throws ( ) {
61
+ using var stream = new UnreadableStream ( ) ;
62
+ var request = new RenewCertificateRequest ( ) ;
63
+
64
+ Assert . Throws < ArgumentException > ( ( ) => request . SetCsr ( stream ) ) ;
65
+ }
54
66
}
Original file line number Diff line number Diff line change @@ -26,6 +26,10 @@ public sealed class RenewCertificateRequest {
26
26
public void SetCsr ( Stream stream , IProgress < double > ? progress = null ) {
27
27
Guard . AgainstNull ( stream , nameof ( stream ) ) ;
28
28
29
+ if ( ! stream . CanRead ) {
30
+ throw new ArgumentException ( "Stream must be readable." , nameof ( stream ) ) ;
31
+ }
32
+
29
33
if ( stream . CanSeek ) {
30
34
stream . Seek ( 0 , SeekOrigin . Begin ) ;
31
35
}
You can’t perform that action at this time.
0 commit comments