Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/af password component #1407

Open
wants to merge 32 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
42bd32b
Initial commit for the AF password box core component
kum-sushil Feb 23, 2024
fadf21a
AF Password Component| Updated license year and few code comments blo…
kum-sushil Feb 23, 2024
7752e1f
AF Password Field| Updated Javascript code, updated apps pom.xml.
kum-sushil Feb 27, 2024
2c322ef
AF Password|Test Cases and html updates supporting responsiveness
kum-sushil Mar 4, 2024
390a3fd
AF Password| Test case updates
kum-sushil Mar 4, 2024
eb470c3
AF Password | PR review comments Updates
kum-sushil Mar 11, 2024
ab5b4e7
AF Password| Cypress test cases for editor and runtime JS
kum-sushil Mar 18, 2024
400da15
AF-Password|PR Comments| Removed Constants from FormConstants to dire…
kum-sushil Apr 27, 2024
57c8c09
AF-password||Resolved test cases and password java for exclusive max …
kum-sushil Jun 5, 2024
0da36ae
Fixing flaky test (#1312)
rismehta Jul 11, 2024
c9f0077
AF Password Field| Updated Javascript code, updated apps pom.xml.
kum-sushil Feb 27, 2024
9ecb0d6
AF Password|Test Cases and html updates supporting responsiveness
kum-sushil Mar 4, 2024
e05f21f
AF Password | PR review comments Updates
kum-sushil Mar 11, 2024
a52e9b2
AF-password||Resolved test cases and password java for exclusive max …
kum-sushil Jun 5, 2024
fa45679
Validation pattern fix
kum-sushil Aug 1, 2024
1f9b1ea
Fixing flaky test (#1312)
rismehta Jul 11, 2024
5a4756c
AF Password Field| Updated Javascript code, updated apps pom.xml.
kum-sushil Feb 27, 2024
858ea43
AF Password|Test Cases and html updates supporting responsiveness
kum-sushil Mar 4, 2024
0f802c6
AF Password | PR review comments Updates
kum-sushil Mar 11, 2024
740bde1
AF-password||Resolved test cases and password java for exclusive max …
kum-sushil Jun 5, 2024
9f036bc
Password Component feature addition for eye open and close icons and …
kum-sushil Sep 17, 2024
e6d0182
GH actions (#1428)
rismehta Sep 30, 2024
a647fc3
AF Password Component| Updated license year and few code comments blo…
kum-sushil Feb 23, 2024
75b6d80
AF Password Field| Updated Javascript code, updated apps pom.xml.
kum-sushil Feb 27, 2024
f93ac9e
AF Password|Test Cases and html updates supporting responsiveness
kum-sushil Mar 4, 2024
0f250b1
AF Password | PR review comments Updates
kum-sushil Mar 11, 2024
d1da0a9
Addressed review comments
Nov 22, 2024
85a3153
Fixing GH workflow
rismehta Nov 28, 2024
2c4303c
AF Password|PR review comments
kum-sushil Nov 29, 2024
ffc3f3b
AF-Password-Component |PR review comments fixes
kum-sushil Jan 6, 2025
d4633cc
Fix commit issues
kum-sushil Jan 14, 2025
f193d34
Fix merge conflict issues
kum-sushil Jan 14, 2025
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
10 changes: 5 additions & 5 deletions .github/workflows/exporter-validate-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ jobs:
exit 1
fi

# Check for changed values
for key in $base_keys; do
base_value=$(echo "$base_file" | jq -r --arg key "$key" '.[$key]')
head_value=$(echo "$head_file" | jq -r --arg key "$key" '.[$key]')
# Check for changed values
for key in $base_keys; do
base_value=$(echo "$base_file" | jq -r ".$key")
head_value=$(echo "$head_file" | jq -r ".$key")

if [ "$base_value" != "$head_value" ]; then
echo "Backward incompatibility change detected in $file. The value of key '$key' was changed from '$base_value' to '$head_value'."
Expand All @@ -64,4 +64,4 @@ jobs:
done

echo "All exporter JSON files have only additions. No backward incompatibility changes detected."
shell: bash
shell: bash
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,6 @@ private FormConstants() {

/* The resource type for the pre-selected the linked panel */
public final static String RT_FD_FORM_REVIEW_DATASOURCE_V1 = RT_FD_FORM_PREFIX + "review/v1/datasource";

public static final String RT_FD_FORM_PASSWORD_V1 = RT_FD_FORM_PREFIX + "password/v1/password";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~ Copyright 2024 Adobe
~
~ 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
~
~ http://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.adobe.cq.forms.core.components.internal.models.v1.form;

import javax.annotation.Nullable;
import javax.annotation.PostConstruct;

import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.models.annotations.Exporter;
import org.apache.sling.models.annotations.Model;
import org.apache.sling.models.annotations.injectorspecific.InjectionStrategy;
import org.apache.sling.models.annotations.injectorspecific.ValueMapValue;

import com.adobe.cq.export.json.ComponentExporter;
import com.adobe.cq.export.json.ExporterConstants;
import com.adobe.cq.forms.core.components.internal.form.FormConstants;
import com.adobe.cq.forms.core.components.models.form.FieldType;
import com.adobe.cq.forms.core.components.models.form.Password;
import com.adobe.cq.forms.core.components.util.AbstractFieldImpl;
import com.adobe.cq.forms.core.components.util.ComponentUtils;

@Model(
adaptables = { SlingHttpServletRequest.class, Resource.class },
adapters = { Password.class, ComponentExporter.class },
resourceType = { FormConstants.RT_FD_FORM_PASSWORD_V1 })
@Exporter(
name = ExporterConstants.SLING_MODEL_EXPORTER_NAME,
extensions = ExporterConstants.SLING_MODEL_EXTENSION)
public class PasswordImpl extends AbstractFieldImpl implements Password {

private Object exclusiveMinimumVaue;
private Object exclusiveMaximumValue;

@ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL)
@Nullable
private String pattern;

@Override
public String getFieldType() {
return getFieldType(FieldType.PASSWORD);
}

@Override
public Integer getMinLength() {
return minLength;
}

@Override
public Integer getMaxLength() {
return maxLength;
}

@Override
public String getFormat() {
return displayFormat;
}

@Override
public String getPattern() {
return pattern;
}

@PostConstruct
private void initPassword() {
exclusiveMaximumValue = ComponentUtils.getExclusiveValue(exclusiveMaximum, maximum, null);
exclusiveMinimumVaue = ComponentUtils.getExclusiveValue(exclusiveMinimum, minimum, null);
// in json either, exclusiveMaximum or maximum should be present
if (exclusiveMaximumValue != null) {
maximum = null;
}
if (exclusiveMinimumVaue != null) {
minimum = null;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~ Copyright 2024 Adobe
~
~ 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
~
~ http://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.adobe.cq.forms.core.components.models.form;

import org.osgi.annotation.versioning.ConsumerType;

/**
* Interface for {@code Password} Sling Model used for the {@code /apps/core/fd/components/form/password/v1/password} component.
*
* @since com.adobe.cq.forms.core.components.models.form 5.11.0
*/
@ConsumerType
public interface Password extends Field, StringConstraint {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~ Copyright 2024 Adobe
~
~ 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
~
~ http://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.adobe.cq.forms.core.components.internal.models.v1.form;

import org.apache.commons.lang3.reflect.FieldUtils;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mockito;

import com.adobe.cq.forms.core.Utils;
import com.adobe.cq.forms.core.components.datalayer.FormComponentData;
import com.adobe.cq.forms.core.components.internal.form.FormConstants;
import com.adobe.cq.forms.core.components.models.form.FieldType;
import com.adobe.cq.forms.core.components.models.form.Password;
import com.adobe.cq.forms.core.context.FormsCoreComponentTestContext;
import io.wcm.testing.mock.aem.junit5.AemContext;
import io.wcm.testing.mock.aem.junit5.AemContextExtension;

import static org.junit.Assert.assertEquals;

@ExtendWith(AemContextExtension.class)
public class PasswordImplTest {

private static final String BASE = "/form/password";
private static final String CONTENT_ROOT = "/content";
private static final String PATH_PASSWORD_DATALAYER = CONTENT_ROOT + "/password-datalayer";
private static final String PATH_PASSWORD_CUSTOMIZED = CONTENT_ROOT + "/password-customized";

private static final String PATH_PASSWORD = CONTENT_ROOT + "/password";

private static final String PATH_PASSWORD_PATTERN = CONTENT_ROOT + "/password-pattern";

private final AemContext context = FormsCoreComponentTestContext.newAemContext();

@BeforeEach
void setUp() {
context.load().json(BASE + FormsCoreComponentTestContext.TEST_CONTENT_JSON, CONTENT_ROOT);
}

@Test
void testExportedType() throws Exception {
Password password = Utils.getComponentUnderTest(PATH_PASSWORD_CUSTOMIZED, Password.class, context);
assertEquals(FormConstants.RT_FD_FORM_PASSWORD_V1, password.getExportedType());
Password passwordMock = Mockito.mock(Password.class);
Mockito.when(passwordMock.getExportedType()).thenCallRealMethod();
assertEquals("", passwordMock.getExportedType());
}

@Test
void testJSONExport() throws Exception {
Password password = Utils.getComponentUnderTest(PATH_PASSWORD_PATTERN, Password.class, context);
Utils.testJSONExport(password, Utils.getTestExporterJSONPath(BASE, PATH_PASSWORD));
}

@Test
void testFieldType() {
Password password = Utils.getComponentUnderTest(PATH_PASSWORD_CUSTOMIZED, Password.class, context);
assertEquals(FieldType.PASSWORD.getValue(), password.getFieldType());
}

@Test
void testGetLabel() {
Password password = Utils.getComponentUnderTest(PATH_PASSWORD_CUSTOMIZED, Password.class, context);
assertEquals("pwd", password.getLabel().getValue());
}

@Test
void testPlaceholder() {
Password password = Utils.getComponentUnderTest(PATH_PASSWORD_CUSTOMIZED, Password.class, context);
assertEquals("Enter valid password", password.getPlaceHolder());
}

@Test
void testGetName() {
Password password = Utils.getComponentUnderTest(PATH_PASSWORD_CUSTOMIZED, Password.class, context);
assertEquals("password", password.getName());

}

@Test
void testDorProperties() {
Password password = Utils.getComponentUnderTest(PATH_PASSWORD_CUSTOMIZED, Password.class, context);
assertEquals(true, password.getDorProperties().get("dorExclusion"));
assertEquals("4", password.getDorProperties().get("dorColspan"));
assertEquals("Text1", password.getDorProperties().get("dorBindRef"));

}

@Test
void testGetDescription() {
Password password = Utils.getComponentUnderTest(PATH_PASSWORD_CUSTOMIZED, Password.class, context);
assertEquals("password field", password.getDescription());
}

@Test
void testGetRequired() {
Password password = Utils.getComponentUnderTest(PATH_PASSWORD_CUSTOMIZED, Password.class, context);
assertEquals(true, password.isRequired());
}

@Test
void testIsEnabled() {
Password password = Utils.getComponentUnderTest(PATH_PASSWORD_CUSTOMIZED, Password.class, context);
assertEquals(true, password.isEnabled());
}

@Test
void testIsEnabledForCustomized() {
Password password = Utils.getComponentUnderTest(PATH_PASSWORD_CUSTOMIZED, Password.class, context);
assertEquals(true, password.isEnabled());
}

@Test
void testIsReadOnly() {
Password password = Utils.getComponentUnderTest(PATH_PASSWORD_CUSTOMIZED, Password.class, context);
assertEquals(false, password.isReadOnly());
}

@Test
void testIsReadOnlyForCustomized() {
Password password = Utils.getComponentUnderTest(PATH_PASSWORD_CUSTOMIZED, Password.class, context);
assertEquals(false, password.isReadOnly());
}

@Test
void testMinLength() {
Password password = Utils.getComponentUnderTest(PATH_PASSWORD_CUSTOMIZED, Password.class, context);
assertEquals(5, password.getMinLength().intValue());
}

@Test
void testMaxLength() {
Password password = Utils.getComponentUnderTest(PATH_PASSWORD_CUSTOMIZED, Password.class, context);
assertEquals(10, password.getMaxLength().intValue());
}

@Test
void testGetDisplayFormat() throws Exception {
Password password = Utils.getComponentUnderTest(PATH_PASSWORD_CUSTOMIZED, Password.class, context);
assertEquals("password", password.getFormat());
}

@Test
void testGetPattern() throws Exception {
Password password = Utils.getComponentUnderTest(PATH_PASSWORD_PATTERN, Password.class, context);
assertEquals("^(?=.*\\d.*\\d)[A-Za-z\\d!@]+$", password.getPattern());
}

@Test
void testDataLayerProperties() throws IllegalAccessException {
Password password = Utils.getComponentUnderTest(PATH_PASSWORD_DATALAYER, Password.class, context);
FieldUtils.writeField(password, "dataLayerEnabled", true, true);
FormComponentData dataObject = (FormComponentData) password.getData();
assert (dataObject != null);
assert (dataObject.getId()).equals("password-1c7bc238a6");
assert (dataObject.getType()).equals("core/fd/components/form/password/v1/password");
assert (dataObject.getTitle()).equals("Full Name");
assert (dataObject.getFieldType()).equals("password");
assert (dataObject.getDescription()).equals("Enter Full Name");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"id": "password-477c777f4e",
"fieldType": "password",
"name": "password1708629052628",
"visible": true,
"description": "<p>long desc</p>\r\n",
"tooltip": "<p>short desc</p>\r\n",
"type": "string",
"required": true,
"enabled": true,
"constraintMessages": {
"required": "Password is required",
"minLength": "min chars",
"maxLength": "max chars",
"pattern": "Invalid pwd"
},
"readOnly": false,
"minLength": 5,
"maxLength": 10,
"exclusiveMinimum" : 8,
"exclusiveMaximum" : 16,
"pattern": "/^(?=.*\\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[a-zA-Z]).{8,}$/",
"label": {
"value": "Password",
"visible": true
},
"properties": {
"afs:layout": {
"tooltipVisible": false
},
"fd:dor": {
"dorExclusion": false
},
"fd:path": "/content/password-customized"
},
"events": {
"custom:setProperty": [
"$event.payload"
]
},
"placeholder": "Enter valid password",
":type": "core/fd/components/form/password/v1/password"
}
Loading
Loading