Allow slashes in authorize-session when using target name (#3249)

This requires specifying `**` as the selector in the proto, which will
match any segments and simply requires that the verb is the last part of
the URL, which it already is.
This commit is contained in:
Jeff Mitchell authored and GitHub committed 2023-05-30 16:03:27 -04:00
1 parent 4d08c52afd
commit c149bc4a79
6 files changed
+154 -120

No files matched your search

+30
View File
@@ -8,6 +8,7 @@ import (
"net/http"
"strings"
"testing"
"time"
"github.com/hashicorp/boundary/api"
"github.com/hashicorp/boundary/api/credentiallibraries"
@@ -21,6 +22,7 @@ import (
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/credential/vault"
"github.com/hashicorp/boundary/internal/daemon/controller"
"github.com/hashicorp/boundary/internal/daemon/worker"
"github.com/hashicorp/boundary/internal/iam"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@@ -733,3 +735,31 @@ func TestUpdateTarget_WhitespaceInAddress(t *testing.T) {
require.NotNil(updateResult)
require.Equal("10.0.0.1", updateResult.Item.Address)
}
// TestCreateTarget_SlashesInName verifies that we can prop'ly route when using
// a target name for authorizing a session and the name contains slashes
func TestCreateTarget_SlashesInName(t *testing.T) {
require := require.New(t)
tc := controller.NewTestController(t, nil)
tw, _ := worker.NewAuthorizedPkiTestWorker(t, tc.ServersRepo(), "test", tc.ClusterAddrs())
require.NotNil(t, tw)
// Wait for worker to become ready
time.Sleep(10 * time.Second)
client := tc.Client()
token := tc.Token()
client.SetToken(token.Token)
_, proj := iam.TestScopes(t, tc.IamRepo(), iam.WithUserId(token.UserId))
tarClient := targets.NewClient(client)
tar, err := tarClient.Create(tc.Context(), "tcp", proj.GetPublicId(), targets.WithName("foo/bar"), targets.WithTcpTargetDefaultPort(2), targets.WithAddress("127.0.0.1"))
require.NoError(err)
require.NotNil(tar)
authzResult, err := tarClient.AuthorizeSession(tc.Context(), "", targets.WithName("foo/bar"), targets.WithScopeId(proj.PublicId))
require.NoError(err)
require.NotNil(authzResult)
}