Skip to content

Commit

Permalink
Add callback tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gsutton authored and garrett-sutton committed Jan 17, 2025
1 parent beedf42 commit 6080576
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions tests/NATS.Client.Core.Tests/NatsConnectionTest.Auth.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,22 @@ NatsOpts.Default with
}),
};

yield return new object[]
{
new Auth(
"NKEY (AuthCallback takes precedence over NKey & Seed)",
"resources/configs/auth/nkey.conf",
NatsOpts.Default with
{
AuthOpts = NatsAuthOpts.Default with
{
AuthCredCallback = async (_, _) => await Task.FromResult(new NatsAuthCred(NatsAuthType.Nkey, "UALQSMXRSAA7ZXIGDDJBJ2JOYJVQIWM3LQVDM5KYIPG4EP3FAGJ47BOJ", "SUAAVWRZG6M5FA5VRRGWSCIHKTOJC7EWNIT4JV3FTOIPO4OBFR5WA7X5TE")),
NKey = "invalid nkey",
Seed = "invalid seed",
},
}),
};

yield return new object[]
{
new Auth(
Expand Down Expand Up @@ -83,6 +99,22 @@ NatsOpts.Default with
}),
};

yield return new object[]
{
new Auth(
"USER-CREDS (AuthCallback takes precedence over Jwt & Seed)",
"resources/configs/auth/operator.conf",
NatsOpts.Default with
{
AuthOpts = NatsAuthOpts.Default with
{
AuthCredCallback = async (_, _) => await Task.FromResult(new NatsAuthCred(NatsAuthType.Jwt, "eyJ0eXAiOiJKV1QiLCJhbGciOiJlZDI1NTE5LW5rZXkifQ.eyJqdGkiOiJOVDJTRkVIN0pNSUpUTzZIQ09GNUpYRFNDUU1WRlFNV0MyWjI1TFk3QVNPTklYTjZFVlhBIiwiaWF0IjoxNjc5MTQ0MDkwLCJpc3MiOiJBREpOSlpZNUNXQlI0M0NOSzJBMjJBMkxPSkVBSzJSS1RaTk9aVE1HUEVCRk9QVE5FVFBZTUlLNSIsIm5hbWUiOiJteS11c2VyIiwic3ViIjoiVUJPWjVMUVJPTEpRRFBBQUNYSk1VRkJaS0Q0R0JaSERUTFo3TjVQS1dSWFc1S1dKM0VBMlc0UloiLCJuYXRzIjp7InB1YiI6e30sInN1YiI6e30sInN1YnMiOi0xLCJkYXRhIjotMSwicGF5bG9hZCI6LTEsInR5cGUiOiJ1c2VyIiwidmVyc2lvbiI6Mn19.ElYEknDixe9pZdl55S9PjduQhhqR1OQLglI1JO7YK7ECYb1mLUjGd8ntcR7ISS04-_yhygSDzX8OS8buBIxMDA", "SUAJR32IC6D45J3URHJ5AOQZWBBO6QTID27NZQKXE3GC5U3SPFEYDJK6RQ")),
Jwt = "not a valid jwt",
Seed = "invalid nkey seed",
},
}),
};

yield return new object[]
{
new Auth(
Expand All @@ -93,6 +125,20 @@ NatsOpts.Default with
AuthOpts = NatsAuthOpts.Default with { CredsFile = "resources/configs/auth/user.creds", },
}),
};

yield return new object[]
{
new Auth(
"Token (AuthCallback takes precedence over Token)",
"resources/configs/auth/token.conf",
NatsOpts.Default with
{
AuthOpts = NatsAuthOpts.Default with {
Token = "won't be used",
AuthCredCallback = async (_, _) => await Task.FromResult(new NatsAuthCred(NatsAuthType.Token, "s3cr3t", string.Empty)),
},
}),
};
}

[Theory]
Expand Down

0 comments on commit 6080576

Please sign in to comment.