-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
184 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2669,7 +2669,22 @@ public void one_time_password_generator_time_based_generates_with_standard_optio | |
Label = "[email protected]", | ||
}; | ||
|
||
pg.ToString().ShouldBe("otpauth://totp/Google:[email protected]?secret=pwq65q55&issuer=Google"); | ||
pg.ToString().ShouldBe("otpauth://totp/Google:test%40google.com?secret=pwq65q55&issuer=Google"); | ||
} | ||
|
||
|
||
[Fact] | ||
[Category("PayloadGenerator/OneTimePassword")] | ||
public void one_time_password_generator_time_based_generates_with_standard_options_escapes_issuer_and_label() | ||
{ | ||
var pg = new PayloadGenerator.OneTimePassword | ||
{ | ||
Secret = "pwq6 5q55", | ||
Issuer = "Google Google", | ||
Label = "test/[email protected]", | ||
}; | ||
|
||
pg.ToString().ShouldBe("otpauth://totp/Google%20Google:test%2Ftest%40google.com?secret=pwq65q55&issuer=Google%20Google"); | ||
} | ||
|
||
|
||
|
@@ -2686,7 +2701,23 @@ public void one_time_password_generator_hmac_based_generates_with_standard_optio | |
Counter = 500, | ||
}; | ||
|
||
pg.ToString().ShouldBe("otpauth://hotp/Google:[email protected]?secret=pwq65q55&issuer=Google&counter=500"); | ||
pg.ToString().ShouldBe("otpauth://hotp/Google:test%40google.com?secret=pwq65q55&issuer=Google&counter=500"); | ||
} | ||
|
||
[Fact] | ||
[Category("PayloadGenerator/OneTimePassword")] | ||
public void one_time_password_generator_hmac_based_generates_with_standard_options_escapes_issuer_and_label() | ||
{ | ||
var pg = new PayloadGenerator.OneTimePassword | ||
{ | ||
Secret = "pwq6 5q55", | ||
Issuer = "Google Google", | ||
Label = "test/[email protected]", | ||
Type = PayloadGenerator.OneTimePassword.OneTimePasswordAuthType.HOTP, | ||
Counter = 500, | ||
}; | ||
|
||
pg.ToString().ShouldBe("otpauth://hotp/Google%20Google:test%2Ftest%40google.com?secret=pwq65q55&issuer=Google%20Google&counter=500"); | ||
} | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
#if !NETCOREAPP1_1 | ||
using QRCoder; | ||
using QRCoderTests.Helpers; | ||
using QRCoderTests.Helpers.XUnitExtenstions; | ||
using Shouldly; | ||
using System; | ||
using System.Drawing; | ||
using System.IO; | ||
using System.Text.RegularExpressions; | ||
using Xunit; | ||
|
||
namespace QRCoderTests | ||
{ | ||
public class PostscriptQRCodeRendererTests | ||
{ | ||
[Fact] | ||
[Category("QRRenderer/PostscriptQRCode")] | ||
public void can_render_postscript_qrcode_simple() | ||
{ | ||
//Create QR code | ||
var gen = new QRCodeGenerator(); | ||
var data = gen.CreateQrCode("This is a quick test! 123#?", QRCodeGenerator.ECCLevel.L); | ||
var ps = new PostscriptQRCode(data).GetGraphic(5); | ||
|
||
var result = HelperFunctions.StringToHash(RemoveCreationDate(ps)); | ||
result.ShouldBe("06b90d1e64bf022a248453e5f91101a0"); | ||
} | ||
|
||
[Fact] | ||
[Category("QRRenderer/PostscriptQRCode")] | ||
public void can_render_postscript_qrcode_eps() | ||
{ | ||
//Create QR code | ||
var gen = new QRCodeGenerator(); | ||
var data = gen.CreateQrCode("This is a quick test! 123#?", QRCodeGenerator.ECCLevel.L); | ||
var ps = new PostscriptQRCode(data).GetGraphic(5, true); | ||
|
||
var result = HelperFunctions.StringToHash(RemoveCreationDate(ps)); | ||
result.ShouldBe("50f6152cdb0b685595d80e7888712d3b"); | ||
} | ||
|
||
[Fact] | ||
[Category("QRRenderer/PostscriptQRCode")] | ||
public void can_render_postscript_qrcode_size() | ||
{ | ||
//Create QR code | ||
var gen = new QRCodeGenerator(); | ||
var data = gen.CreateQrCode("This is a quick test! 123#?", QRCodeGenerator.ECCLevel.L); | ||
var ps = new PostscriptQRCode(data).GetGraphic(new Size(33, 33)); | ||
|
||
var result = HelperFunctions.StringToHash(RemoveCreationDate(ps)); | ||
result.ShouldBe("49c7faaafef312eb4b6ea1fec195e63d"); | ||
} | ||
|
||
[Fact] | ||
[Category("QRRenderer/PostscriptQRCode")] | ||
public void can_render_postscript_qrcode_size_no_quiet_zones() | ||
{ | ||
//Create QR code | ||
var gen = new QRCodeGenerator(); | ||
var data = gen.CreateQrCode("This is a quick test! 123#?", QRCodeGenerator.ECCLevel.L); | ||
var ps = new PostscriptQRCode(data).GetGraphic(new Size(50, 50), false); | ||
|
||
var result = HelperFunctions.StringToHash(RemoveCreationDate(ps)); | ||
result.ShouldBe("9bfa0468e125d9815a39902133a10762"); | ||
} | ||
|
||
[Fact] | ||
[Category("QRRenderer/PostscriptQRCode")] | ||
public void can_render_postscript_qrcode_colors() | ||
{ | ||
//Create QR code | ||
var gen = new QRCodeGenerator(); | ||
var data = gen.CreateQrCode("This is a quick test! 123#?", QRCodeGenerator.ECCLevel.L); | ||
var ps = new PostscriptQRCode(data).GetGraphic(5, Color.Red, Color.Blue); | ||
|
||
var result = HelperFunctions.StringToHash(RemoveCreationDate(ps)); | ||
result.ShouldBe("2e001d7f67a446eb1b5df32ff5321808"); | ||
} | ||
|
||
private static string RemoveCreationDate(string text) | ||
{ | ||
// Regex pattern to match lines that start with %%CreationDate: followed by any characters until the end of the line | ||
string pattern = @"%%CreationDate:.*\r?\n?"; | ||
|
||
// Use Regex.Replace to remove matching lines | ||
return Regex.Replace(text, pattern, string.Empty, RegexOptions.Multiline); | ||
} | ||
} | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters