|
| 1 | +/* |
| 2 | + * Copyright 2020-Present The Serverless Workflow Specification Authors |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package io.serverlessworkflow.impl.test; |
| 17 | + |
| 18 | +import static org.assertj.core.api.Assertions.assertThatThrownBy; |
| 19 | + |
| 20 | +import io.serverlessworkflow.api.types.Workflow; |
| 21 | +import io.serverlessworkflow.fluent.spec.WorkflowBuilder; |
| 22 | +import io.serverlessworkflow.fluent.spec.dsl.DSL; |
| 23 | +import io.serverlessworkflow.impl.WorkflowApplication; |
| 24 | +import java.net.URI; |
| 25 | +import org.junit.jupiter.api.Test; |
| 26 | + |
| 27 | +class UndefinedAuthReferenceTest { |
| 28 | + |
| 29 | + @Test |
| 30 | + void httpWithUndefinedAuthReferenceShouldFailAtBuildTime() { |
| 31 | + Workflow workflow = |
| 32 | + WorkflowBuilder.workflow("undefined-auth-ref-http", "test", "0.1.0") |
| 33 | + .tasks( |
| 34 | + DSL.call( |
| 35 | + DSL.http() |
| 36 | + .method("GET") |
| 37 | + .uri( |
| 38 | + URI.create("http://localhost:10110/dir/index.html"), |
| 39 | + a -> a.use("sampleDigest")))) |
| 40 | + .build(); |
| 41 | + try (WorkflowApplication app = WorkflowApplication.builder().build()) { |
| 42 | + assertThatThrownBy(() -> app.workflowDefinition(workflow)) |
| 43 | + .isInstanceOf(IllegalArgumentException.class) |
| 44 | + .hasMessageContaining("sampleDigest") |
| 45 | + .hasMessageContaining("not defined in use.authentications"); |
| 46 | + } |
| 47 | + } |
| 48 | + |
| 49 | + @Test |
| 50 | + void openApiWithUndefinedAuthReferenceShouldFailAtBuildTime() { |
| 51 | + Workflow workflow = |
| 52 | + WorkflowBuilder.workflow("undefined-auth-ref-openapi", "test", "0.1.0") |
| 53 | + .tasks( |
| 54 | + DSL.call( |
| 55 | + DSL.openapi() |
| 56 | + .document("http://localhost:10110/openapi.json") |
| 57 | + .operation("getPet") |
| 58 | + .authentication(a -> a.use("sampleDigest")))) |
| 59 | + .build(); |
| 60 | + try (WorkflowApplication app = WorkflowApplication.builder().build()) { |
| 61 | + assertThatThrownBy(() -> app.workflowDefinition(workflow)) |
| 62 | + .isInstanceOf(IllegalArgumentException.class) |
| 63 | + .hasMessageContaining("sampleDigest") |
| 64 | + .hasMessageContaining("not defined in use.authentications"); |
| 65 | + } |
| 66 | + } |
| 67 | +} |
0 commit comments