macaroons: add GetCustomCaveatCondition func

This adds a `GetCustomCaveatCondition` function that returns the custom
caveat condition for a given macaroon and caveat name. Previously there
was no function for getting the custom caveat condition from a macaroon,
only for setting one.
This commit is contained in:
Daniel McNally committed 2022-01-24 11:39:00 -05:00
1 parent f50950640f
commit a4474447c2
2 files changed
+44

No files matched your search

+10
View File
@@ -132,6 +132,11 @@ func TestCustomConstraint(t *testing.T) {
require.False(t, macaroons.HasCustomCaveat(testMacaroon, "something"))
require.False(t, macaroons.HasCustomCaveat(nil, "foo"))
customCaveatCondition := macaroons.GetCustomCaveatCondition(
testMacaroon, "unit-test",
)
require.Equal(t, customCaveatCondition, "test-value")
// Custom caveats don't necessarily need a value, just the name is fine
// too to create a tagged macaroon.
constraintFunc = macaroons.CustomConstraint("unit-test", "")
@@ -144,4 +149,9 @@ func TestCustomConstraint(t *testing.T) {
require.True(t, macaroons.HasCustomCaveat(testMacaroon, "unit-test"))
require.False(t, macaroons.HasCustomCaveat(testMacaroon, "test-value"))
require.False(t, macaroons.HasCustomCaveat(testMacaroon, "something"))
customCaveatCondition = macaroons.GetCustomCaveatCondition(
testMacaroon, "unit-test",
)
require.Equal(t, customCaveatCondition, "")
}