generated from kyma-project/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Validation of the 3rd party payload (#236)
<!-- Thank you for your contribution. Before you submit the pull request: 1. Follow contributing guidelines, templates, the recommended Git workflow, and any related documentation. 2. Read and submit the required Contributor Licence Agreements (https://github.com/kyma-project/community/blob/main/CONTRIBUTING.md#agreements-and-licenses). 3. Test your changes and attach their results to the pull request. 4. Update the relevant documentation. If the pull request requires a decision, follow the [decision-making process](https://github.com/kyma-project/community/blob/main/governance.md) and replace the PR template with the [decision record template](https://github.com/kyma-project/community/blob/main/.github/ISSUE_TEMPLATE/decision-record.md). --> **Description** Changes proposed in this pull request: - verify if the runtimeID, that comes from external service Compass is in the correct UUID format - validate the URL of the token to the Compass Connector to ensure it points to the SAP domain - perform a sanity check on the Token itself **Related issue(s)** #54
- Loading branch information
Showing
7 changed files
with
140 additions
and
13 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package controllers | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/kyma-incubator/compass/components/director/pkg/graphql" | ||
"github.com/kyma-project/compass-manager/internal/director/mocks" | ||
"github.com/sirupsen/logrus" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestAppError(t *testing.T) { | ||
t.Run("should succeed after fetching correct Compass Token", func(t *testing.T) { | ||
mockDirectorClient := mocks.Client{} | ||
mockDirectorClient.On("GetConnectionToken", "compassID", "globalAccount").Return(graphql.OneTimeTokenForRuntimeExt{ | ||
OneTimeTokenForRuntime: graphql.OneTimeTokenForRuntime{ | ||
TokenWithURL: graphql.TokenWithURL{ | ||
Token: "dGVzdFRva2VuQmFzZWQ2NA==", | ||
ConnectorURL: "kyma.cloud.sap/connector/graphql", | ||
}, | ||
}, | ||
}, nil) | ||
|
||
configurator := NewRuntimeAgentConfigurator(&mockDirectorClient, "kyma.cloud.sap/connector/graphql", logrus.New()) | ||
|
||
token, err := configurator.fetchCompassToken("compassID", "globalAccount") | ||
require.NoError(t, err) | ||
assert.Equal(t, "kyma.cloud.sap/connector/graphql", token.ConnectorURL) | ||
assert.Equal(t, "dGVzdFRva2VuQmFzZWQ2NA==", token.Token) | ||
}) | ||
t.Run("should return error after fetching invalid Connector URL", func(t *testing.T) { | ||
mockDirectorClient := mocks.Client{} | ||
mockDirectorClient.On("GetConnectionToken", "compassID", "globalAccount").Return(graphql.OneTimeTokenForRuntimeExt{ | ||
OneTimeTokenForRuntime: graphql.OneTimeTokenForRuntime{ | ||
TokenWithURL: graphql.TokenWithURL{ | ||
Token: "dGVzdFRva2VuQmFzZWQ2NA==", | ||
ConnectorURL: "invalid.domain/connector/graphql", | ||
}, | ||
}, | ||
}, nil) | ||
|
||
configurator := NewRuntimeAgentConfigurator(&mockDirectorClient, "kyma.cloud.sap/connector/graphql", logrus.New()) | ||
|
||
token, err := configurator.fetchCompassToken("compassID", "globalAccount") | ||
require.Error(t, err) | ||
require.ErrorContains(t, err, "Connector URL does not match the expected pattern") | ||
assert.Equal(t, token, graphql.OneTimeTokenForRuntimeExt{}) | ||
}) | ||
t.Run("should return error when Runtime Token is too long", func(t *testing.T) { | ||
mockDirectorClient := mocks.Client{} | ||
mockDirectorClient.On("GetConnectionToken", "compassID", "globalAccount").Return(graphql.OneTimeTokenForRuntimeExt{ | ||
OneTimeTokenForRuntime: graphql.OneTimeTokenForRuntime{ | ||
TokenWithURL: graphql.TokenWithURL{ | ||
Token: "bm90LWJhc2U2NC1lbmNvZGVkbm90LWJhc2U2NC1lbmNvZGVkbm90LWJhc2U2NC1lbmNvZGVkbm90LWJhc2U2NC1lbmNvZGVkbm90LWJhc2U2NC1lbmNvZGVkbm90LWJhc2U2NC1lbmNvZGVkbm90LWJhc2U2NC1lbmNvZGVkbm90LWJhc2U2NC1lbmNvZGVkbm90LWJhc2U2NC1lbmNvZGVk", | ||
ConnectorURL: "kyma.cloud.sap/connector/graphql", | ||
}, | ||
}, | ||
}, nil) | ||
|
||
configurator := NewRuntimeAgentConfigurator(&mockDirectorClient, "kyma.cloud.sap/connector/graphql", logrus.New()) | ||
|
||
token, err := configurator.fetchCompassToken("compassID", "globalAccount") | ||
require.Error(t, err) | ||
require.ErrorContains(t, err, "OneTimeToken is too long") | ||
assert.Equal(t, token, graphql.OneTimeTokenForRuntimeExt{}) | ||
}) | ||
} |
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
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