Skip to content

Commit

Permalink
fix protos and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
skpratt committed Sep 12, 2023
1 parent 546493f commit 08faeb8
Show file tree
Hide file tree
Showing 25 changed files with 2,047 additions and 1,504 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"id": {
"type": {
"group": "auth",
"group_version": "v1alpha1",
"kind": "TrafficPermissions"
},
"tenancy": {
"partition": "default",
"namespace": "default",
"peer_name": "local"
},
"name": "tp-8"
},
"data": {
"@type": "hashicorp.consul.auth.v1alpha1.TrafficPermissions",
"destination": {
"identity_name": "wi-1"
},
"action": "ACTION_ALLOW",
"permissions": [
{
"sources": [
{
"identity_name": "wi-2",
"identity_prefix": "wi-",
"namespace": "ns1",
"partition": "ap1",
"peer": "cp1",
"sameness_group": "sg1"
}
],
"destination_rules": [
{
"port_names": [
"baz"
]
}
]
}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"id": {
"type": {
"group": "auth",
"group_version": "v1alpha1",
"kind": "TrafficPermissions"
},
"tenancy": {
"partition": "default",
"namespace": "default",
"peer_name": "local"
},
"name": "tp-7"
},
"data": {
"@type": "hashicorp.consul.auth.v1alpha1.TrafficPermissions",
"destination": {},
"action": "ACTION_ALLOW",
"permissions": [
{
"sources": [
{
"identity_name": "wi-3"
}
],
"destination_rules": [
{
"port_names": [
"baz"
]
}
]
}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"id": {
"type": {
"group": "auth",
"group_version": "v1alpha1",
"kind": "TrafficPermissions"
},
"tenancy": {
"partition": "default",
"namespace": "default",
"peer_name": "local"
},
"name": "tp-6"
},
"data": {
"@type": "hashicorp.consul.auth.v1alpha1.TrafficPermissions",
"destination": {
"identity_name": "wi-1"
},
"action": "ACTION_ALLOW",
"permissions": [
{
"sources": [],
"destination_rules": [
{
"port_names": [
"baz"
]
}
]
}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"id": {
"type": {
"group": "auth",
"group_version": "v1alpha1",
"kind": "TrafficPermissions"
},
"tenancy": {
"partition": "default",
"namespace": "default",
"peer_name": "local"
},
"name": "tp-5"
},
"data": {
"@type": "hashicorp.consul.auth.v1alpha1.TrafficPermissions",
"destination": {
"identity_name": "wi-1",
"identity_prefix": "wi"
},
"action": "ACTION_ALLOW",
"permissions": [
{
"sources": [
{
"identity_name": "wi-3"
}
],
"destination_rules": [
{
"port_names": [
"baz"
]
}
]
}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"id": {
"type": {
"group": "auth",
"group_version": "v1alpha1",
"kind": "TrafficPermissions"
},
"tenancy": {
"partition": "default",
"namespace": "default",
"peer_name": "local"
},
"name": "tp-4"
},
"data": {
"@type": "hashicorp.consul.auth.v1alpha1.TrafficPermissions",
"destination": {
"identity_name": "wi-1"
},
"action": "ACTION_ALLOW",
"permissions": [
{
"sources": [
{
"identity_name": "wi-3"
}
],
"destination_rules": [
{
"path_exact": "somepath",
"path_prefix": "some",
"port_names": [
"baz"
]
}
]
}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"id": {
"type": {
"group": "auth",
"group_version": "v1alpha1",
"kind": "TrafficPermissions"
},
"tenancy": {
"partition": "default",
"namespace": "default",
"peer_name": "local"
},
"name": "tp-3"
},
"data": {
"@type": "hashicorp.consul.auth.v1alpha1.TrafficPermissions",
"destination": {
"identity_name": "wi-1"
},
"action": 0,
"permissions": [
{
"sources": [
{
"identity_name": "wi-3"
}
],
"destination_rules": [
{
"port_names": [
"baz"
]
}
]
}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"id": {
"type": {
"group": "auth",
"group_version": "v1alpha1",
"kind": "TrafficPermissions"
},
"tenancy": {
"partition": "default",
"namespace": "default",
"peer_name": "local"
},
"name": "tp-1"
},
"data": {
"@type": "hashicorp.consul.auth.v1alpha1.TrafficPermissions",
"destination": {
"identity_name": "wi-1"
},
"action": "ACTION_ALLOW",
"permissions": [
{
"sources": [
{
"identity_name": "wi-2"
}
],
"destination_rules": [
{
"port_names": [
"foo"
]
}
]
}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"id": {
"type": {
"group": "auth",
"group_version": "v1alpha1",
"kind": "TrafficPermissions"
},
"tenancy": {
"partition": "default",
"namespace": "default",
"peer_name": "local"
},
"name": "tp-2"
},
"data": {
"@type": "hashicorp.consul.auth.v1alpha1.TrafficPermissions",
"destination": {
"identity_prefix": "wi-"
},
"action": "ACTION_DENY",
"permissions": [
{
"sources": [
{
"identity_prefix": "wi-",
"namespace": "ns1",
"partition": "ap1"
}
],
"destination_rules": [
{
"path_exact": "somepath",
"port_names": [
"foo"
]
}
]
}
]
}
}
39 changes: 39 additions & 0 deletions internal/auth/authtest/run_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1
package authtest

import (
"testing"

svctest "github.com/hashicorp/consul/agent/grpc-external/services/resource/testing"
"github.com/hashicorp/consul/internal/auth"
"github.com/hashicorp/consul/internal/controller"
"github.com/hashicorp/consul/internal/resource/reaper"
"github.com/hashicorp/consul/proto-public/pbresource"
"github.com/hashicorp/consul/sdk/testutil"
)

func runInMemResourceService(t *testing.T) pbresource.ResourceServiceClient {
t.Helper()

ctx := testutil.TestContext(t)

// Create the in-mem resource service
client := svctest.RunResourceService(t, auth.RegisterTypes)

// Setup/Run the controller manager
mgr := controller.NewManager(client, testutil.Logger(t))

// We also depend on the reaper to take care of cleaning up owned health statuses and
// service endpoints so we must enable that controller as well
reaper.RegisterControllers(mgr)
mgr.SetRaftLeader(true)
go mgr.Run(ctx)

return client
}

func TestResource_Validation(t *testing.T) {
client := runInMemResourceService(t)
RunAuthV1Alpha1IntegrationTest(t, client)
}
Loading

0 comments on commit 08faeb8

Please sign in to comment.