Skip to content

Commit

Permalink
chore: Consistency updates
Browse files Browse the repository at this point in the history
chore: Add test for checking default table output options

chore: Add default table output columns in resource bundles
  • Loading branch information
rsenden committed Apr 5, 2023
1 parent a0b022b commit 3030448
Show file tree
Hide file tree
Showing 13 changed files with 45 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,16 @@

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;
import picocli.CommandLine.Command;
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,16 @@

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;
import picocli.CommandLine.Command;
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,16 @@

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;
import picocli.CommandLine.Command;
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,16 @@

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;
import picocli.CommandLine.Command;
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 11 additions & 1 deletion src/test/java/com/fortify/cli/FortifyCLITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit 3030448

Please sign in to comment.