Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace Google.Authenticator.Tests
{
public class QRCodeTest
public class QRCodeAndSetupUrlTests
{
[Theory]
[InlineData("issuer", "otpauth://totp/issuer:a%40b.com?secret=ONSWG4TFOQ&issuer=issuer")]
Expand All @@ -25,8 +25,13 @@ public void CanGenerateQRCode(string issuer, string expectedUrl)
2);

var actualUrl = ExtractUrlFromQRImage(setupCodeInfo.QrCodeSetupImageUrl);
var rawUrl = setupCodeInfo.SetupUrl;

actualUrl.ShouldBe(expectedUrl);
Assert.Multiple(() =>
{
actualUrl.ShouldBe(expectedUrl, "QR Code Url is not as expected");
rawUrl.ShouldBe(expectedUrl, "SetupUrl is not as expected");
});
}

[Theory]
Expand All @@ -44,8 +49,13 @@ public void CanGenerateSHA256QRCode(string issuer, string expectedUrl)
2);

var actualUrl = ExtractUrlFromQRImage(setupCodeInfo.QrCodeSetupImageUrl);
var rawUrl = setupCodeInfo.SetupUrl;

actualUrl.ShouldBe(expectedUrl);
Assert.Multiple(() =>
{
actualUrl.ShouldBe(expectedUrl, "QR Code Url is not as expected");
rawUrl.ShouldBe(expectedUrl, "SetupUrl is not as expected");
});
}

[Theory]
Expand All @@ -63,8 +73,13 @@ public void CanGenerateSHA512QRCode(string issuer, string expectedUrl)
2);

var actualUrl = ExtractUrlFromQRImage(setupCodeInfo.QrCodeSetupImageUrl);
var rawUrl = setupCodeInfo.SetupUrl;

actualUrl.ShouldBe(expectedUrl);
Assert.Multiple(() =>
{
actualUrl.ShouldBe(expectedUrl, "QR Code Url is not as expected");
rawUrl.ShouldBe(expectedUrl, "SetupUrl is not as expected");
});
}

private static string ExtractUrlFromQRImage(string qrCodeSetupImageUrl)
Expand Down
8 changes: 7 additions & 1 deletion Google.Authenticator/SetupCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,19 @@ public class SetupCode
/// </summary>
public string QrCodeSetupImageUrl { get; internal set; }

/// <summary>
/// The Raw otp:// url
/// </summary>
public string SetupUrl { get; internal set; }

public SetupCode() { }

public SetupCode(string account, string manualEntryKey, string qrCodeSetupImageUrl)
public SetupCode(string account, string manualEntryKey, string qrCodeSetupImageUrl, string setupUrl)
{
Account = account;
ManualEntryKey = manualEntryKey;
QrCodeSetupImageUrl = qrCodeSetupImageUrl;
SetupUrl = setupUrl;
}
}
}
3 changes: 2 additions & 1 deletion Google.Authenticator/TwoFactorAuthenticator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ public SetupCode GenerateSetupCode(string issuer,
return new SetupCode(
accountTitleNoSpaces,
encodedSecretKey.Trim('='),
generateQrCode ? GenerateQrCodeUrl(qrPixelsPerModule, provisionUrl) : "");
generateQrCode ? GenerateQrCodeUrl(qrPixelsPerModule, provisionUrl) : "",
provisionUrl);
}

private static string GenerateQrCodeUrl(int qrPixelsPerModule, string provisionUrl)
Expand Down
12 changes: 12 additions & 0 deletions build/azure-pipeline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ jobs:
- script: dotnet build ./Google.Authenticator.Tests/Google.Authenticator.Tests.csproj --configuration $(buildConfiguration) --no-restore --no-dependencies
displayName: build tests

- task: UseDotNet@2
displayName: Install dotnet 6
inputs:
packageType: sdk
version: 6.x

- task: UseDotNet@2
displayName: Install dotnet 7
inputs:
packageType: sdk
version: 7.x

- task: DotNetCoreCLI@2
displayName: test
inputs:
Expand Down