Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release/5.1.x] Merge pull request #8836 from rundeck/RUN-2156 #8840

Merged
merged 2 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,11 @@ class WebhookService {
if(saveWebhookRequest.id) {
hook = webhookDataProvider.getWebhookByUuid(saveWebhookRequest.uuid)
if (!hook) return [err: "Webhook not found"]

shouldUpdate = true
if(saveWebhookRequest.roles && !hookData.importData) {
try {
rundeckAuthTokenManagerService.updateAuthRoles(authContext, hook.authToken,rundeckAuthTokenManagerService.parseAuthRoles(hookData.roles))
shouldUpdate = true
validateNulls(hook, saveWebhookRequest)
} catch (Exception e) {
return [err: "Failed to update Auth Token roles: "+e.message]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,42 @@ class WebhookServiceSpec extends Specification implements ServiceUnitTest<Webhoo
imported= [uuid: "d1c6dcf7-dd12-4858-9373-c12639c689d4", name: "test", project: "Test2", authToken: "12345", eventPlugin: "log-webhook-event"]
}

def "import a webhook that already exits in a project"() {
given:"webhook exists with token in project A"
def mockUserAuth = Mock(UserAndRolesAuthContext) {
getUsername() >> { "webhookUser" }
getRoles() >> { ["webhook", "test"] }
}
service.apiService = Mock(MockApiService)
service.rundeckAuthTokenManagerService = Mock(AuthTokenManager) {
parseAuthRoles(_) >> { ["webhook", "test"] }
}
service.userService = Mock(MockUserService) {
validateUserExists(_) >> { true }
}
service.pluginService = Mock(MockPluginService) {
validatePluginConfig(_, _, _) >> { return new ValidatedPlugin(report: new Validator.Report(), valid: true) }
getPlugin(_, _) >> { new TestWebhookEventPlugin() }
listPlugins(WebhookEventPlugin) >> { ["log-webhook-event": new TestWebhookEventPlugin()] }
}
def webhookUUID="c1c6dcf7-dd12-4858-9373-c12639c689d4"
def definition= [uuid: webhookUUID, name: "test", project: "Test", authToken: "12345", eventPlugin: "log-webhook-event"]

Webhook existing = new Webhook(definition)
existing.save()


when:"import data with same token into project A"
def result = service.importWebhook(mockUserAuth, definition, false)


then:"should have 1 webhook"
def existingWebhooks = service.webhookDataProvider.findAllByProject("Test")
result == [msg:'Webhook test imported']
existingWebhooks.size() == 1

}

def "getWebhookWithAuth"() {
setup:
Webhook hook = new Webhook()
Expand Down