From 3030448c1c6091b7e53a62ccb3f4e6719bdafc54 Mon Sep 17 00:00:00 2001 From: Ruud Senden <8635138+rsenden@users.noreply.github.com> Date: Wed, 5 Apr 2023 19:04:50 +0200 Subject: [PATCH] chore: Consistency updates chore: Add test for checking default table output options chore: Add default table output columns in resource bundles --- .../com/fortify/cli/common/util/DisableTest.java | 4 +++- .../cli/config/i18n/ConfigMessages.properties | 7 +++++++ .../fod/entity/rest/cli/cmd/FoDRestCallCommand.java | 3 +++ .../com/fortify/cli/fod/i18n/FoDMessages.properties | 2 ++ .../entity/rest/cli/cmd/SCDastRestCallCommand.java | 3 +++ .../cli/sc_dast/i18n/SCDastMessages.properties | 1 + .../cli/cmd/SCSastControllerRestCallCommand.java | 3 +++ .../cli/sc_sast/i18n/SCSastMessages.properties | 1 + .../ssc/entity/rest/cli/cmd/SSCRestCallCommand.java | 3 +++ .../com/fortify/cli/ssc/i18n/SSCMessages.properties | 1 + .../variable/cli/cmd/VariableContentsCommand.java | 3 +++ .../fortify/cli/state/i18n/StateMessages.properties | 5 ++++- src/test/java/com/fortify/cli/FortifyCLITest.java | 12 +++++++++++- 13 files changed, 45 insertions(+), 3 deletions(-) diff --git a/fcli-common/src/main/java/com/fortify/cli/common/util/DisableTest.java b/fcli-common/src/main/java/com/fortify/cli/common/util/DisableTest.java index 7adff376ea..fcb59d809c 100644 --- a/fcli-common/src/main/java/com/fortify/cli/common/util/DisableTest.java +++ b/fcli-common/src/main/java/com/fortify/cli/common/util/DisableTest.java @@ -33,6 +33,8 @@ public enum TestType { CMD_NAME, // Check for proper command usage header CMD_USAGE_HEADER, + // Check default table options present in resource bundle + CMD_DEFAULT_TABLE_OPTIONS_PRESENT, // Check maximum command depth CMD_DEPTH, // Check option names are in kebab-case @@ -52,6 +54,6 @@ public enum TestType { // Check option doesn't have an empty description OPT_EMPTY_DESCRIPTION, // Check that mixins don't have @Spec(MIXEE) - INJECT_MIXEE, + INJECT_MIXEE, } } diff --git a/fcli-config/src/main/resources/com/fortify/cli/config/i18n/ConfigMessages.properties b/fcli-config/src/main/resources/com/fortify/cli/config/i18n/ConfigMessages.properties index bf46dc839c..2d6502a5a7 100644 --- a/fcli-config/src/main/resources/com/fortify/cli/config/i18n/ConfigMessages.properties +++ b/fcli-config/src/main/resources/com/fortify/cli/config/i18n/ConfigMessages.properties @@ -39,3 +39,10 @@ fcli.config.truststore.set.usage.header = Configure SSL trust store fcli.config.truststore.set.trustStorePath = Path to custom SSL trust store fcli.config.truststore.set.truststore-password = SSL trust store password fcli.config.truststore.set.truststore-type = SSL trust store type (jks, pkcs12) + +################################################################################################################# +# The following are technical properties that shouldn't be internationalized #################################### +################################################################################################################# + +# Table output columns configuration +fcli.config.delete-all.output.table.options = name,type \ No newline at end of file diff --git a/fcli-fod/src/main/java/com/fortify/cli/fod/entity/rest/cli/cmd/FoDRestCallCommand.java b/fcli-fod/src/main/java/com/fortify/cli/fod/entity/rest/cli/cmd/FoDRestCallCommand.java index 20f91c99de..773f89a1f8 100644 --- a/fcli-fod/src/main/java/com/fortify/cli/fod/entity/rest/cli/cmd/FoDRestCallCommand.java +++ b/fcli-fod/src/main/java/com/fortify/cli/fod/entity/rest/cli/cmd/FoDRestCallCommand.java @@ -26,6 +26,8 @@ import com.fortify.cli.common.output.cli.mixin.OutputHelperMixins; import com.fortify.cli.common.rest.cli.cmd.AbstractRestCallCommand; +import com.fortify.cli.common.util.DisableTest; +import com.fortify.cli.common.util.DisableTest.TestType; import com.fortify.cli.fod.output.mixin.FoDProductHelperMixin; import lombok.Getter; @@ -33,6 +35,7 @@ import picocli.CommandLine.Mixin; @Command(name = OutputHelperMixins.RestCall.CMD_NAME) +@DisableTest(TestType.CMD_DEFAULT_TABLE_OPTIONS_PRESENT) // Output columns depend on response contents public final class FoDRestCallCommand extends AbstractRestCallCommand { @Getter @Mixin private OutputHelperMixins.RestCall outputHelper; @Getter @Mixin private FoDProductHelperMixin productHelper; diff --git a/fcli-fod/src/main/resources/com/fortify/cli/fod/i18n/FoDMessages.properties b/fcli-fod/src/main/resources/com/fortify/cli/fod/i18n/FoDMessages.properties index f2bbee0edd..587049e6aa 100644 --- a/fcli-fod/src/main/resources/com/fortify/cli/fod/i18n/FoDMessages.properties +++ b/fcli-fod/src/main/resources/com/fortify/cli/fod/i18n/FoDMessages.properties @@ -404,3 +404,5 @@ fcli.fod.user-group.output.header.id = Id fcli.fod.user-group.output.header.name = Name fcli.fod.user-group.output.header.assignedUsersCount = Assigned Users fcli.fod.user-group.output.header.assignedApplicationsCount = Assigned Applications + +fcli.fod.session.output.table.options = name,type,url,created,expires,expired diff --git a/fcli-sc-dast/src/main/java/com/fortify/cli/sc_dast/entity/rest/cli/cmd/SCDastRestCallCommand.java b/fcli-sc-dast/src/main/java/com/fortify/cli/sc_dast/entity/rest/cli/cmd/SCDastRestCallCommand.java index d633a89e74..d40a2c5860 100644 --- a/fcli-sc-dast/src/main/java/com/fortify/cli/sc_dast/entity/rest/cli/cmd/SCDastRestCallCommand.java +++ b/fcli-sc-dast/src/main/java/com/fortify/cli/sc_dast/entity/rest/cli/cmd/SCDastRestCallCommand.java @@ -26,6 +26,8 @@ import com.fortify.cli.common.output.cli.mixin.OutputHelperMixins; import com.fortify.cli.common.rest.cli.cmd.AbstractRestCallCommand; +import com.fortify.cli.common.util.DisableTest; +import com.fortify.cli.common.util.DisableTest.TestType; import com.fortify.cli.sc_dast.output.cli.mixin.SCDastProductHelperMixin; import lombok.Getter; @@ -33,6 +35,7 @@ import picocli.CommandLine.Mixin; @Command(name = OutputHelperMixins.RestCall.CMD_NAME) +@DisableTest(TestType.CMD_DEFAULT_TABLE_OPTIONS_PRESENT) // Output columns depend on response contents public final class SCDastRestCallCommand extends AbstractRestCallCommand { @Getter @Mixin private OutputHelperMixins.RestCall outputHelper; @Getter @Mixin SCDastProductHelperMixin productHelper; diff --git a/fcli-sc-dast/src/main/resources/com/fortify/cli/sc_dast/i18n/SCDastMessages.properties b/fcli-sc-dast/src/main/resources/com/fortify/cli/sc_dast/i18n/SCDastMessages.properties index 1bc37ffd7d..0c6ace6a21 100644 --- a/fcli-sc-dast/src/main/resources/com/fortify/cli/sc_dast/i18n/SCDastMessages.properties +++ b/fcli-sc-dast/src/main/resources/com/fortify/cli/sc_dast/i18n/SCDastMessages.properties @@ -176,6 +176,7 @@ fcli.env.default.prefix=FCLI_DEFAULT # Table output columns configuration #TODO Add start URL's? +fcli.sc-dast.session.output.table.options = name,type,url,created,expires,expired fcli.sc-dast.scan.output.table.options = id,name,applicationName,applicationVersionName,scanStatus,lowCount,mediumCount,highCount,criticalCount fcli.sc-dast.scan-policy.output.table.options = category,id,name fcli.sc-dast.scan-settings.output.table.options = id,name,applicationName,applicationVersionName,policyName,cicdToken,modifiedDateTime diff --git a/fcli-sc-sast/src/main/java/com/fortify/cli/sc_sast/entity/rest/cli/cmd/SCSastControllerRestCallCommand.java b/fcli-sc-sast/src/main/java/com/fortify/cli/sc_sast/entity/rest/cli/cmd/SCSastControllerRestCallCommand.java index 2bc04032eb..b2979cfcc8 100644 --- a/fcli-sc-sast/src/main/java/com/fortify/cli/sc_sast/entity/rest/cli/cmd/SCSastControllerRestCallCommand.java +++ b/fcli-sc-sast/src/main/java/com/fortify/cli/sc_sast/entity/rest/cli/cmd/SCSastControllerRestCallCommand.java @@ -26,6 +26,8 @@ import com.fortify.cli.common.output.cli.mixin.OutputHelperMixins; import com.fortify.cli.common.rest.cli.cmd.AbstractRestCallCommand; +import com.fortify.cli.common.util.DisableTest; +import com.fortify.cli.common.util.DisableTest.TestType; import com.fortify.cli.sc_sast.output.cli.mixin.SCSastControllerProductHelperMixin; import lombok.Getter; @@ -33,6 +35,7 @@ import picocli.CommandLine.Mixin; @Command(name = OutputHelperMixins.RestCall.CMD_NAME) +@DisableTest(TestType.CMD_DEFAULT_TABLE_OPTIONS_PRESENT) // Output columns depend on response contents public final class SCSastControllerRestCallCommand extends AbstractRestCallCommand { @Getter @Mixin private OutputHelperMixins.RestCall outputHelper; @Getter @Mixin private SCSastControllerProductHelperMixin productHelper; diff --git a/fcli-sc-sast/src/main/resources/com/fortify/cli/sc_sast/i18n/SCSastMessages.properties b/fcli-sc-sast/src/main/resources/com/fortify/cli/sc_sast/i18n/SCSastMessages.properties index a067239078..6cdf0efa75 100644 --- a/fcli-sc-sast/src/main/resources/com/fortify/cli/sc_sast/i18n/SCSastMessages.properties +++ b/fcli-sc-sast/src/main/resources/com/fortify/cli/sc_sast/i18n/SCSastMessages.properties @@ -76,4 +76,5 @@ fcli.sc-sast.scan.output.header.sscArtifactState = Ssc processing state fcli.env.default.prefix=FCLI_DEFAULT # Table output columns configuration +fcli.sc-sast.session.output.table.options = name,type,url,created,expires,expired fcli.sc-sast.scan.output.table.options = jobToken,hasFiles,scanState,scaProgress,sscUploadState,sscArtifactState,endpointVersion diff --git a/fcli-ssc/src/main/java/com/fortify/cli/ssc/entity/rest/cli/cmd/SSCRestCallCommand.java b/fcli-ssc/src/main/java/com/fortify/cli/ssc/entity/rest/cli/cmd/SSCRestCallCommand.java index c0b61cb83a..34b09687ec 100644 --- a/fcli-ssc/src/main/java/com/fortify/cli/ssc/entity/rest/cli/cmd/SSCRestCallCommand.java +++ b/fcli-ssc/src/main/java/com/fortify/cli/ssc/entity/rest/cli/cmd/SSCRestCallCommand.java @@ -26,6 +26,8 @@ import com.fortify.cli.common.output.cli.mixin.OutputHelperMixins; import com.fortify.cli.common.rest.cli.cmd.AbstractRestCallCommand; +import com.fortify.cli.common.util.DisableTest; +import com.fortify.cli.common.util.DisableTest.TestType; import com.fortify.cli.ssc.output.cli.mixin.SSCProductHelperMixin; import lombok.Getter; @@ -33,6 +35,7 @@ import picocli.CommandLine.Mixin; @Command(name = OutputHelperMixins.RestCall.CMD_NAME) +@DisableTest(TestType.CMD_DEFAULT_TABLE_OPTIONS_PRESENT) // Output columns depend on response contents public final class SSCRestCallCommand extends AbstractRestCallCommand { @Getter @Mixin private OutputHelperMixins.RestCall outputHelper; @Getter @Mixin private SSCProductHelperMixin productHelper; diff --git a/fcli-ssc/src/main/resources/com/fortify/cli/ssc/i18n/SSCMessages.properties b/fcli-ssc/src/main/resources/com/fortify/cli/ssc/i18n/SSCMessages.properties index b6abe11aff..525f1719c8 100644 --- a/fcli-ssc/src/main/resources/com/fortify/cli/ssc/i18n/SSCMessages.properties +++ b/fcli-ssc/src/main/resources/com/fortify/cli/ssc/i18n/SSCMessages.properties @@ -280,6 +280,7 @@ fcli.ssc.report-template.generate-answerfile.output.table.options = path # TODO Rename allApplicationRole to universalAccess in command implementation fcli.ssc.role.output.table.options = id,name,builtIn,allApplicationRole,description fcli.ssc.role-permission.output.table.options = id,name,dependsOnPermission,description +fcli.ssc.session.output.table.options = name,type,url,created,expires,expired fcli.ssc.token.output.table.options = id,username,type,creationDate,terminalDate,timeRemaining,description fcli.ssc.token.create.output.table.options = id,username,type,restToken,applicationToken,terminalDate,timeRemaining,description fcli.ssc.token.revoke.output.table.options = responseCode diff --git a/fcli-state/src/main/java/com/fortify/cli/state/variable/cli/cmd/VariableContentsCommand.java b/fcli-state/src/main/java/com/fortify/cli/state/variable/cli/cmd/VariableContentsCommand.java index 13aa5f13ca..6a03552c82 100644 --- a/fcli-state/src/main/java/com/fortify/cli/state/variable/cli/cmd/VariableContentsCommand.java +++ b/fcli-state/src/main/java/com/fortify/cli/state/variable/cli/cmd/VariableContentsCommand.java @@ -27,6 +27,8 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fortify.cli.common.output.cli.cmd.AbstractOutputCommand; import com.fortify.cli.common.output.cli.cmd.IJsonNodeSupplier; +import com.fortify.cli.common.util.DisableTest; +import com.fortify.cli.common.util.DisableTest.TestType; import com.fortify.cli.state.variable.cli.mixin.VariableOutputHelperMixins; import com.fortify.cli.state.variable.cli.mixin.VariableResolverMixin; @@ -35,6 +37,7 @@ import picocli.CommandLine.Mixin; @Command(name = VariableOutputHelperMixins.Contents.CMD_NAME) +@DisableTest(TestType.CMD_DEFAULT_TABLE_OPTIONS_PRESENT) // Output columns depend on variable contents public class VariableContentsCommand extends AbstractOutputCommand implements IJsonNodeSupplier { @Getter @Mixin private VariableOutputHelperMixins.Contents outputHelper; @Mixin private VariableResolverMixin.PositionalParameter variableResolver; diff --git a/fcli-state/src/main/resources/com/fortify/cli/state/i18n/StateMessages.properties b/fcli-state/src/main/resources/com/fortify/cli/state/i18n/StateMessages.properties index f865401d19..87d81d83ce 100644 --- a/fcli-state/src/main/resources/com/fortify/cli/state/i18n/StateMessages.properties +++ b/fcli-state/src/main/resources/com/fortify/cli/state/i18n/StateMessages.properties @@ -19,4 +19,7 @@ fcli.state.variable.contents.usage.header = Get fcli variable contents ################################################################################################################# # Table output columns configuration -fcli.config.variable.output.table.options = created,accessed,name,defaultPropertyName,singular,encrypted +fcli.state.delete-all.output.table.options = name,type +# Empty on purpose; output columns depend on variable contents, so we don't want default variable columns +fcli.state.variable.contents.output.table.options = +fcli.state.variable.output.table.options = created,accessed,name,defaultPropertyName,singular,encrypted diff --git a/src/test/java/com/fortify/cli/FortifyCLITest.java b/src/test/java/com/fortify/cli/FortifyCLITest.java index ff8fb00a84..39b24a3978 100644 --- a/src/test/java/com/fortify/cli/FortifyCLITest.java +++ b/src/test/java/com/fortify/cli/FortifyCLITest.java @@ -13,6 +13,7 @@ import org.junit.jupiter.api.Test; import com.fortify.cli.app.FCLIRootCommands; +import com.fortify.cli.common.output.writer.CommandSpecMessageResolver; import com.fortify.cli.common.util.DisableTest; import com.fortify.cli.common.util.DisableTest.TestType; import com.fortify.cli.common.util.PicocliSpecHelper; @@ -64,9 +65,18 @@ private void checkContainerCommand(Results results, CommandSpec spec) { } private void checkLeafCommand(Results results, CommandSpec spec) { - // TODO Any tests specific for leaf commands? + checkDefaultTableOptionsPresent(results, spec); } + private void checkDefaultTableOptionsPresent(Results results, CommandSpec spec) { + if ( spec.mixins().containsKey("outputHelper") ) { + var tableOptions = new CommandSpecMessageResolver(spec).getMessageString("output.table.options"); + if ( StringUtils.isBlank(tableOptions) ) { + results.add(TestType.CMD_DEFAULT_TABLE_OPTIONS_PRESENT, Level.WARN, spec, "No *.output.table.options defined to specify default table output columns"); + } + } + } + private void checkOptions(Results results, CommandSpec cmdSpec) { checkStandardOptions(results, cmdSpec); cmdSpec.options().forEach(optionSpec->checkOptionSpec(results, cmdSpec, optionSpec));