Skip to content

Commit

Permalink
fix sonar findings (#699)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkroepke authored Apr 8, 2022
1 parent 552dcaa commit 736e256
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 28 deletions.
10 changes: 0 additions & 10 deletions contrib/charts/keycloak-config-cli/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,3 @@ app.kubernetes.io/name: {{ include "keycloak-config-cli.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "keycloak-config-cli.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "keycloak-config-cli.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
3 changes: 0 additions & 3 deletions contrib/charts/keycloak-config-cli/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ existingSecret: ""
# The key in the existing secret that stores the password
existingSecretKey: password

# The name of the service account to use.
serviceAccount: ""

securityContext: {}
containerSecurityContext: {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class UserImportService {
private static final Logger logger = LoggerFactory.getLogger(UserImportService.class);

private static final String[] IGNORED_PROPERTIES_FOR_UPDATE = {"realmRoles", "clientRoles"};
private static final String INITIAL_PASSWORD_USER_LABEL = "initial";
private static final String USER_LABEL_FOR_INITIAL_CREDENTIAL = "initial";

private final RealmRepository realmRepository;
private final UserRepository userRepository;
Expand Down Expand Up @@ -148,7 +148,9 @@ private void updateUser(UserRepresentation existingUser) {
if (patchedUser.getCredentials() != null) {
// do not override password, if userLabel is set "initial"
List<CredentialRepresentation> userCredentials = patchedUser.getCredentials().stream()
.filter(credentialRepresentation -> !Objects.equals(credentialRepresentation.getUserLabel(), INITIAL_PASSWORD_USER_LABEL))
.filter(credentialRepresentation -> !Objects.equals(
credentialRepresentation.getUserLabel(), USER_LABEL_FOR_INITIAL_CREDENTIAL
))
.collect(Collectors.toList());
patchedUser.setCredentials(userCredentials);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ private static boolean canBeIdOrPlaceholder(String str) {
return !str.contains(".");
}

@SuppressWarnings("BooleanMethodIsAlwaysInverted")
public boolean isPlaceholder() {
return idOrPlaceholder.startsWith("$");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import static org.mockserver.model.HttpResponse.response;

@MockServerTest("mockServerUrl=http://localhost:${mockServerPort}")
@SuppressWarnings({"java:S5976"})
class KeycloakImportProviderIT extends AbstractImportTest {
private MockServerClient mockServerClient;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1103,7 +1103,7 @@ void shouldSetAuthenticationFlowBindingOverrides() throws IOException {
assertThat(realm.getRealm(), is(REALM_NAME));
assertThat(realm.isEnabled(), is(true));

// Check is flow are imported, only check existence since there is many tests case on AuthFlow
// Check is flow are imported, only check existence since there is many tests' case on AuthFlow
assertThat(getAuthenticationFlow(realm, "custom flow"), notNullValue());
assertThat(getAuthenticationFlow(realm, "custom flow 2"), notNullValue());

Expand Down Expand Up @@ -1138,7 +1138,7 @@ void shouldUpdateAuthenticationFlowBindingOverrides() throws IOException {
assertThat(realm.getRealm(), is(REALM_NAME));
assertThat(realm.isEnabled(), is(true));

// Check is flow are imported, only check existence since there is many tests case on AuthFlow
// Check is flow are imported, only check existence since there is many tests' case on AuthFlow
assertThat(getAuthenticationFlow(realm, "custom flow"), notNullValue());
assertThat(getAuthenticationFlow(realm, "custom flow 2"), notNullValue());

Expand Down Expand Up @@ -1173,7 +1173,7 @@ void shouldNotChangeAuthenticationFlowBindingOverrides() throws IOException {
assertThat(realm.getRealm(), is(REALM_NAME));
assertThat(realm.isEnabled(), is(true));

// Check is flow are imported, only check existence since there is many tests case on AuthFlow
// Check is flow are imported, only check existence since there is many tests' case on AuthFlow
assertThat(getAuthenticationFlow(realm, "custom flow"), notNullValue());
assertThat(getAuthenticationFlow(realm, "custom flow 2"), notNullValue());

Expand Down Expand Up @@ -1208,7 +1208,7 @@ void shouldUpdateAuthenticationFlowBindingOverridesIdWhenFlowChanged() throws IO
assertThat(realm.getRealm(), is(REALM_NAME));
assertThat(realm.isEnabled(), is(true));

// Check is flow are imported, only check existence since there is many tests case on AuthFlow
// Check is flow are imported, only check existence since there is many tests' case on AuthFlow
assertThat(getAuthenticationFlow(realm, "custom flow"), notNullValue());
assertThat(getAuthenticationFlow(realm, "custom flow 2"), notNullValue());

Expand Down Expand Up @@ -1246,7 +1246,7 @@ void shouldntUpdateWithAnInvalidAuthenticationFlowBindingOverrides() throws IOEx
assertThat(realm.getRealm(), is(REALM_NAME));
assertThat(realm.isEnabled(), is(true));

// Check is flow are imported, only check existence since there is many tests case on AuthFlow
// Check is flow are imported, only check existence since there is many tests' case on AuthFlow
assertThat(getAuthenticationFlow(realm, "custom flow"), notNullValue());
assertThat(getAuthenticationFlow(realm, "custom flow 2"), notNullValue());

Expand Down Expand Up @@ -1281,7 +1281,7 @@ void shouldRemoveAuthenticationFlowBindingOverrides() throws IOException {
assertThat(realm.getRealm(), is(REALM_NAME));
assertThat(realm.isEnabled(), is(true));

// Check is flow are imported, only check existence since there is many tests case on AuthFlow
// Check is flow are imported, only check existence since there is many tests' case on AuthFlow
assertThat(getAuthenticationFlow(realm, "custom flow"), notNullValue());
assertThat(getAuthenticationFlow(realm, "custom flow 2"), notNullValue());

Expand Down Expand Up @@ -1497,7 +1497,7 @@ void shouldCreateRealmWithClientWithAuthenticationFlowBindingOverrides() throws
assertThat(realm.getRealm(), is(REALM_AUTH_FLOW_NAME));
assertThat(realm.isEnabled(), is(true));

// Check is flow are imported, only check existence since there is many tests case on AuthFlow
// Check is flow are imported, only check existence since there is many tests' case on AuthFlow
assertThat(getAuthenticationFlow(realm, "custom flow"), notNullValue());

ClientRepresentation client = getClientByName(realm, "moped-client");
Expand Down Expand Up @@ -2288,9 +2288,9 @@ void shouldTriggerErrorWhenReferencingMissingObjectsByNameInFineGrainedAuthz() t
@Order(50)
void shouldNotTriggerErrorWhenReferencingInvalidUuidInFineGrainedAuthz() throws IOException {
// These scenarios do not use placeholders and instead reference objects by UUID - which do not need to exist.
// Keycloak accepts this and it sometimes even works (for objects that allow specifying UUID in creation and are created after the import)
// Keycloak accepts this, and it sometimes even works (for objects that allow specifying UUID in creation and are created after the import)
// This is how to partially support fine-grained authz for types that are not supported yet by keycloak-config-cli
// keycloak-config-cli will log a warning, but otherwise the import succeeds
// will log a warning, but otherwise the import succeeds

RealmImport foundImport0 = getFirstImport("50.0_update_realm_update_authz_policy_for_unknown_type_with_id_realm-management.json");
assertDoesNotThrow(() -> realmImportService.doImport(foundImport0));
Expand All @@ -2317,7 +2317,7 @@ void shouldAddClientWithAuthenticationFlowBindingOverrides() throws IOException
assertThat(realm.getRealm(), is(REALM_AUTH_FLOW_NAME));
assertThat(realm.isEnabled(), is(true));

// Check is flow are imported, only check existence since there is many tests case on AuthFlow
// Check is flow are imported, only check existence since there is many tests' case on AuthFlow
assertThat(getAuthenticationFlow(realm, "custom flow"), notNullValue());

ClientRepresentation client = getClientByName(realm, "moped-client");
Expand Down Expand Up @@ -2366,7 +2366,7 @@ void shouldClearAuthenticationFlowBindingOverrides() throws IOException {
assertThat(realm.getRealm(), is(REALM_AUTH_FLOW_NAME));
assertThat(realm.isEnabled(), is(true));

// Check is flow are imported, only check existence since there is many tests case on AuthFlow
// Check is flow are imported, only check existence since there is many tests' case on AuthFlow
assertThat(getAuthenticationFlow(realm, "custom flow"), notNullValue());

ClientRepresentation client = getClientByName(realm, "moped-client");
Expand Down Expand Up @@ -2413,7 +2413,7 @@ void shouldSetAuthenticationFlowBindingOverridesByIds() throws IOException {
assertThat(realm.getRealm(), is(REALM_AUTH_FLOW_NAME));
assertThat(realm.isEnabled(), is(true));

// Check is flow are imported, only check existence since there is many tests case on AuthFlow
// Check is flow are imported, only check existence since there is many tests' case on AuthFlow
assertThat(getAuthenticationFlow(realm, "custom exported flow"), notNullValue());

ClientRepresentation client = getClientByName(realm, "moped-client");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ void shouldUpdateComponentUpdateSubComponent() throws IOException {

/*
@Test
@Disabled("subComponent will be a empty map instead a null value. subComponent will deleted instead skipped")
@Disabled("subComponent will be an empty map instead a null value. subComponent will deleted instead skipped")
@Order(9)
void shouldUpdateComponentSkipSubComponent() throws IOException {
doImport("09_update_realm__update_component_skip_subcomponent.json");
Expand Down

0 comments on commit 736e256

Please sign in to comment.