-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Organization tokens have been broken since they were refactored in 104013d. The JWT contains the _organization token_ _ID_ but the middleware was checking the _organization_ _name_. Might fix #658.
- Loading branch information
Showing
10 changed files
with
210 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package integration | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/leg100/otf/internal" | ||
"github.com/leg100/otf/internal/api" | ||
"github.com/leg100/otf/internal/organization" | ||
"github.com/leg100/otf/internal/workspace" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
// TestIntegration_OrganizationTokens demonstrates the use of an organization | ||
// token to authenticate via the API. | ||
func TestIntegration_OrganizationTokens(t *testing.T) { | ||
integrationTest(t) | ||
|
||
daemon, org, ctx := setup(t, nil) | ||
|
||
ot, token, err := daemon.CreateOrganizationToken(ctx, organization.CreateOrganizationTokenOptions{ | ||
Organization: org.Name, | ||
}) | ||
require.NoError(t, err) | ||
assert.Equal(t, org.Name, ot.Organization) | ||
|
||
apiClient, err := api.NewClient(api.Config{ | ||
Address: daemon.Hostname(), | ||
Token: string(token), | ||
}) | ||
require.NoError(t, err) | ||
|
||
// create some workspaces and attempt to list them using client | ||
// authenticating with an organization token | ||
daemon.createWorkspace(t, ctx, org) | ||
daemon.createWorkspace(t, ctx, org) | ||
daemon.createWorkspace(t, ctx, org) | ||
|
||
wsClient := &workspace.Client{Client: apiClient} | ||
got, err := wsClient.ListWorkspaces(ctx, workspace.ListOptions{ | ||
Organization: internal.String(org.Name), | ||
}) | ||
require.NoError(t, err) | ||
assert.Equal(t, 3, len(got.Items)) | ||
|
||
// re-generate token | ||
_, _, err = daemon.CreateOrganizationToken(ctx, organization.CreateOrganizationTokenOptions{ | ||
Organization: org.Name, | ||
}) | ||
require.NoError(t, err) | ||
|
||
// access with previous token should now be refused | ||
_, err = wsClient.ListWorkspaces(ctx, workspace.ListOptions{ | ||
Organization: internal.String(org.Name), | ||
}) | ||
require.Equal(t, internal.ErrUnauthorized, err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.