Skip to content
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 @@ -20,6 +20,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;

/**
Expand Down Expand Up @@ -193,6 +194,30 @@ enum AuthorizationType {
public String getName() {
return name().toLowerCase();
}

/**
* Returns true if value converts to valid authorisation type enumeration. NONE is not valid type as it should
* signal absence of authorisation mechanism.
*
* @param value authorisation name
* @return false if value converts to NONE or value does not mach any of enumeration names, otherwise returns
* true
*/
public static boolean isApplicable(String value) {
if (value == null) {
return false;
}

for (AuthorizationType authorizationType : values()) {
String name = authorizationType.getName();

if ((authorizationType != NONE) && Objects.equals(value.toLowerCase(), name.toLowerCase())) {
return true;
}
}

return false;
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/*
* Copyright 2023-present ByteChef Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.bytechef.component.definition;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

/**
* @author Igor Beslic
*/
public class AuthorizationTest {

@Test
public void testAuthorizationAuthorizationTypeIsApplicable() {

for (String applicableValue : getRandomApplicableValues()) {
Assertions.assertTrue(
Authorization.AuthorizationType.isApplicable(applicableValue), applicableValue + " is valid");
}

for (String nonApplicableValue : getRandomNonApplicableValues()) {
Assertions.assertFalse(
Authorization.AuthorizationType.isApplicable(nonApplicableValue), nonApplicableValue + " is valid");
}

}

private static Random random = new Random();

private List<String> getRandomApplicableValues() {
Authorization.AuthorizationType[] values = Authorization.AuthorizationType.values();

List<String> names = new ArrayList<>();

for (Authorization.AuthorizationType value : values) {
if (value == Authorization.AuthorizationType.NONE) {
continue;
}

String name = value.getName();

if (random.nextBoolean()) {
names.add(name.toLowerCase());

continue;
}

if (random.nextBoolean()) {
char charToReplace = name.charAt(random.nextInt(name.length()));

if (charToReplace == 95) {
continue;
}

names.add(name.replace(charToReplace, (char) (charToReplace - 32)));

continue;
}

names.add(name);

}

return names;
}

private List<String> getRandomNonApplicableValues() {
List<String> randomApplicableValues = getRandomApplicableValues();

List<String> nonApplicableValues = new ArrayList<>();

for (String randomApplicableValue : randomApplicableValues) {
nonApplicableValues.add(randomApplicableValue + "_wrong");
}

nonApplicableValues.add("none");
nonApplicableValues.add("None");
nonApplicableValues.add("nOne");
nonApplicableValues.add("noNe");
nonApplicableValues.add("nonE");
nonApplicableValues.add("NonE");
nonApplicableValues.add("nOnE");
nonApplicableValues.add("noNE");
nonApplicableValues.add("NoNE");
nonApplicableValues.add("nONE");
nonApplicableValues.add("NONE");

return nonApplicableValues;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
public class HttpClientConnection {

public static final ModifiableConnectionDefinition CONNECTION_DEFINITION = connection()
.properties(string(BASE_URI).label("Base URI"))
.properties(string(BASE_URI).label("Base URI")
.description("If set, it will be combined HTTP Client Component URI attribute value."))
.authorizationRequired(false)
.authorizations(
authorization(Authorization.AuthorizationType.API_KEY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ public class HttpClientComponentConstants {

string(URI)
.label("URI")
.description("The URI to make the request to")
.description(
"The URI to make the request to. If HTTP Client Connection defines Base URI, then this value is appended to it.")
.exampleValue("/")
.placeholder("https://example.com/index.html")
.defaultValue("")
.required(true),
Expand Down
Loading
Loading