2021-10-01 13:59:55 +00:00
|
|
|
//go:build !ent
|
2021-06-07 19:41:33 +00:00
|
|
|
|
|
|
|
package nomad
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/hashicorp/consul/api"
|
2022-03-15 12:42:43 +00:00
|
|
|
"github.com/hashicorp/nomad/ci"
|
2021-06-07 19:41:33 +00:00
|
|
|
"github.com/hashicorp/nomad/command/agent/consul"
|
|
|
|
"github.com/hashicorp/nomad/helper/testlog"
|
2023-01-28 00:15:51 +00:00
|
|
|
"github.com/shoenig/test/must"
|
2021-06-07 19:41:33 +00:00
|
|
|
)
|
|
|
|
|
2021-06-08 22:20:10 +00:00
|
|
|
func TestConsulACLsAPI_hasSufficientPolicy_oss(t *testing.T) {
|
2022-03-15 12:42:43 +00:00
|
|
|
ci.Parallel(t)
|
2021-06-07 19:41:33 +00:00
|
|
|
|
|
|
|
try := func(t *testing.T, namespace, task string, token *api.ACLToken, exp bool) {
|
|
|
|
logger := testlog.HCLogger(t)
|
|
|
|
cAPI := &consulACLsAPI{
|
|
|
|
aclClient: consul.NewMockACLsAPI(logger),
|
|
|
|
logger: logger,
|
|
|
|
}
|
|
|
|
result, err := cAPI.canWriteService(namespace, task, token)
|
2023-01-28 00:15:51 +00:00
|
|
|
must.NoError(t, err)
|
|
|
|
must.Eq(t, exp, result)
|
2021-06-07 19:41:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// In Nomad OSS, group consul namespace will always be empty string.
|
|
|
|
|
|
|
|
t.Run("no namespace with default token", func(t *testing.T) {
|
|
|
|
t.Run("no useful policy or role", func(t *testing.T) {
|
|
|
|
try(t, "", "service1", consul.ExampleOperatorToken0, false)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("working policy only", func(t *testing.T) {
|
|
|
|
try(t, "", "service1", consul.ExampleOperatorToken1, true)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("working role only", func(t *testing.T) {
|
|
|
|
try(t, "", "service1", consul.ExampleOperatorToken4, true)
|
|
|
|
})
|
2023-01-28 00:15:51 +00:00
|
|
|
|
|
|
|
t.Run("working service identity only", func(t *testing.T) {
|
|
|
|
try(t, "", "service1", consul.ExampleOperatorToken6, true)
|
|
|
|
})
|
2021-06-07 19:41:33 +00:00
|
|
|
})
|
|
|
|
}
|