Skip to content

Commit

Permalink
[tests] Skip SecRecord tests on macOS 11 (xamarin#15825)
Browse files Browse the repository at this point in the history
It may hang on the bots.
  • Loading branch information
rolfbjarne authored Sep 9, 2022
1 parent b6cdde4 commit 61e8ce4
Show file tree
Hide file tree
Showing 3 changed files with 171 additions and 93 deletions.
50 changes: 25 additions & 25 deletions tests/monotouch-test/Security/KeyChainTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ public void Add_Certificate ()
#endif
NSData data = NSData.FromStream (certStream);

var query = new SecRecord (SecKind.Certificate) {
Label = $"Internet Widgits Pty Ltd",
};
var query = RecordTest.CreateSecRecord (SecKind.Certificate,
label: $"Internet Widgits Pty Ltd"
);
var rec = query.Clone ();
rec.SetValueRef (new SecCertificate (data));

Expand All @@ -62,7 +62,7 @@ public void AddQueryRemove_Identity ()
{
if (TestRuntime.CheckXcodeVersion (13, 0))
Assert.Ignore ("code == errSecInternal (-26276)");
using (SecRecord rec = new SecRecord (SecKind.Identity))
using (var rec = RecordTest.CreateSecRecord (SecKind.Identity))
using (var id = IdentityTest.GetIdentity ()) {
rec.SetValueRef (id);
SecStatusCode code = SecKeyChain.Add (rec);
Expand All @@ -72,7 +72,7 @@ public void AddQueryRemove_Identity ()
if (!TestRuntime.CheckXcodeVersion (5, 0))
Assert.Inconclusive ("QueryAsConcreteType does not work before iOS7");

using (SecRecord rec = new SecRecord (SecKind.Identity)) {
using (var rec = RecordTest.CreateSecRecord (SecKind.Identity)) {
SecStatusCode code;
var match = SecKeyChain.QueryAsConcreteType (rec, out code);
if ((match == null) && (code == SecStatusCode.ItemNotFound))
Expand Down Expand Up @@ -148,10 +148,10 @@ string RecordAccount {
Guid GetID ()
{
SecStatusCode code;
SecRecord queryRec = new SecRecord (SecKind.GenericPassword) {
Service = RecordService,
Account = RecordAccount,
};
var queryRec = RecordTest.CreateSecRecord (SecKind.GenericPassword,
service: RecordService,
account: RecordAccount
);
var queryResponse = SecKeyChain.QueryAsRecord (queryRec, out code);
if (code == SecStatusCode.Success && queryResponse?.Generic != null)
return new Guid (NSString.FromData (queryResponse.Generic, NSStringEncoding.UTF8));
Expand All @@ -163,10 +163,10 @@ Guid GetID ()
public void QueryAsData ()
{
SecStatusCode code;
SecRecord queryRec = new SecRecord (SecKind.GenericPassword) {
Service = RecordService,
Account = RecordAccount,
};
var queryRec = RecordTest.CreateSecRecord (SecKind.GenericPassword,
service: RecordService,
account: RecordAccount
);
var data = SecKeyChain.QueryAsData (queryRec, true, out code);
if (code == SecStatusCode.Success && queryRec != null) {
Assert.NotNull (data.Bytes);
Expand All @@ -177,10 +177,10 @@ public void QueryAsData ()
public void QueryAsDataArray ()
{
SecStatusCode code;
SecRecord queryRec = new SecRecord (SecKind.GenericPassword) {
Service = RecordService,
Account = RecordAccount,
};
var queryRec = RecordTest.CreateSecRecord (SecKind.GenericPassword,
service: RecordService,
account: RecordAccount
);
var data = SecKeyChain.QueryAsData (queryRec, true, 1, out code);
if (code == SecStatusCode.Success && queryRec != null) {
Assert.NotNull (data [0].Bytes);
Expand All @@ -189,19 +189,19 @@ public void QueryAsDataArray ()

SecStatusCode RemoveID ()
{
var queryRec = new SecRecord (SecKind.GenericPassword) {
Service = RecordService,
Account = RecordAccount,
};
var queryRec = RecordTest.CreateSecRecord (SecKind.GenericPassword,
service: RecordService,
account: RecordAccount
);
return SecKeyChain.Remove (queryRec);
}

SecStatusCode SetID (Guid setID)
{
var queryRec = new SecRecord (SecKind.GenericPassword) {
Service = RecordService,
Account = RecordAccount,
};
var queryRec = RecordTest.CreateSecRecord (SecKind.GenericPassword,
service: RecordService,
account: RecordAccount
);
var record = queryRec.Clone ();
record.Generic = NSData.FromString (Convert.ToString (setID), NSStringEncoding.UTF8);
record.Accessible = SecAccessible.Always;
Expand Down
20 changes: 10 additions & 10 deletions tests/monotouch-test/Security/KeyTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ static X509Certificate2 c {

public static void DeleteKeysWithLabel (string label)
{
var query = new SecRecord (SecKind.Key) {
Label = label,
};
var query = RecordTest.CreateSecRecord (SecKind.Key,
label: label
);
SecStatusCode code;
do {
// For some reason each call to SecKeyChain will only remove a single key, so do a loop.
Expand Down Expand Up @@ -118,7 +118,7 @@ public void RoundtripRSAMinPKCS1 ()
var label = $"KeyTest.RoundtripRSAMinPKCS1-{CFBundle.GetMain ().Identifier}-{GetType ().FullName}-{Process.GetCurrentProcess ().Id}";

try {
using (var record = new SecRecord (SecKind.Key)) {
using (var record = RecordTest.CreateSecRecord (SecKind.Key)) {
record.KeyType = SecKeyType.RSA;
record.KeySizeInBits = MinRsaKeySize; // it's not a performance test :)
record.Label = label;
Expand Down Expand Up @@ -208,7 +208,7 @@ public void EncryptTooLarge ()
var label = $"KeyTest.EncryptTooLarge-{CFBundle.GetMain ().Identifier}-{GetType ().FullName}-{Process.GetCurrentProcess ().Id}";

try {
using (var record = new SecRecord (SecKind.Key)) {
using (var record = RecordTest.CreateSecRecord (SecKind.Key)) {
record.KeyType = SecKeyType.RSA;
record.KeySizeInBits = MinRsaKeySize; // it's not a performance test :)
record.Label = label;
Expand Down Expand Up @@ -245,7 +245,7 @@ public void RoundtripRSA1024OAEP ()
var label = $"KeyTest.RoundtripRSA1024OAEP-{CFBundle.GetMain ().Identifier}-{GetType ().FullName}-{Process.GetCurrentProcess ().Id}";

try {
using (var record = new SecRecord (SecKind.Key)) {
using (var record = RecordTest.CreateSecRecord (SecKind.Key)) {
record.KeyType = SecKeyType.RSA;
record.KeySizeInBits = 1024; // it's not a performance test :)
record.Label = label;
Expand Down Expand Up @@ -299,7 +299,7 @@ public void SignVerifyRSAMinPKCS1SHA1 ()
var label = $"KeyTest.SignVerifyRSAMinPKCS1SHA1-{CFBundle.GetMain ().Identifier}-{GetType ().FullName}-{Process.GetCurrentProcess ().Id}";

try {
using (var record = new SecRecord (SecKind.Key)) {
using (var record = RecordTest.CreateSecRecord (SecKind.Key)) {
record.KeyType = SecKeyType.RSA;
record.KeySizeInBits = MinRsaKeySize; // it's not a performance test :)
record.Label = label;
Expand Down Expand Up @@ -335,7 +335,7 @@ public void SignVerifyECSHA1 ()
var label = $"KeyTest.SignVerifyECSHA1-{CFBundle.GetMain ().Identifier}-{GetType ().FullName}-{Process.GetCurrentProcess ().Id}";

try {
using (var record = new SecRecord (SecKind.Key)) {
using (var record = RecordTest.CreateSecRecord (SecKind.Key)) {
record.KeyType = SecKeyType.EC;
record.KeySizeInBits = 256; // it's not a performance test :)
record.Label = label;
Expand Down Expand Up @@ -371,7 +371,7 @@ public void GenerateKeyPairTooLargeRSA ()
var label = $"KeyTest.GenerateKeyPairTooLargeRSA-{CFBundle.GetMain ().Identifier}-{GetType ().FullName}-{Process.GetCurrentProcess ().Id}";

try {
using (var record = new SecRecord (SecKind.Key)) {
using (var record = RecordTest.CreateSecRecord (SecKind.Key)) {
record.KeyType = SecKeyType.RSA;
// maximum documented as 2048, .NET maximum is 16384
record.KeySizeInBits = 16384;
Expand Down Expand Up @@ -437,7 +437,7 @@ public void BenchmarkNative4096 ()
var label = $"KeyTest.BenchmarkNative4096-{CFBundle.GetMain ().Identifier}-{GetType ().FullName}-{Process.GetCurrentProcess ().Id}";

try {
using (var record = new SecRecord (SecKind.Key)) {
using (var record = RecordTest.CreateSecRecord (SecKind.Key)) {
record.KeyType = SecKeyType.RSA;
record.KeySizeInBits = 4096;
record.Label = label;
Expand Down
Loading

0 comments on commit 61e8ce4

Please sign in to comment.