Skip to content

Commit 47364d1

Browse files
authored
Merge pull request #1235 from commercetools/SUPPORT-36587/customer-password-validation-external-auth
SUPPORT-36587: password is not required when authMode is external
2 parents c0cf253 + 1f1144d commit 47364d1

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

src/main/java/com/commercetools/sync/customers/helpers/CustomerBatchValidator.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import static org.apache.commons.lang3.StringUtils.isBlank;
66

77
import com.commercetools.api.models.common.BaseAddress;
8+
import com.commercetools.api.models.customer.AuthenticationMode;
89
import com.commercetools.api.models.customer.CustomerDraft;
910
import com.commercetools.sync.commons.helpers.BaseBatchValidator;
1011
import com.commercetools.sync.customers.CustomerSyncOptions;
@@ -107,7 +108,8 @@ private boolean isValidCustomerDraft(@Nullable final CustomerDraft customerDraft
107108
handleError(format(CUSTOMER_DRAFT_KEY_NOT_SET, customerDraft.getEmail()));
108109
} else if (isBlank(customerDraft.getEmail())) {
109110
handleError(format(CUSTOMER_DRAFT_EMAIL_NOT_SET, customerDraft.getKey()));
110-
} else if (isBlank(customerDraft.getPassword())) {
111+
} else if (isBlank(customerDraft.getPassword())
112+
&& customerDraft.getAuthenticationMode() != AuthenticationMode.EXTERNAL_AUTH) {
111113
handleError(format(CUSTOMER_DRAFT_PASSWORD_NOT_SET, customerDraft.getKey()));
112114
} else if (hasValidAddresses(customerDraft)) {
113115
return hasValidBillingAndShippingAddresses(customerDraft);

src/main/java/com/commercetools/sync/customers/utils/CustomerReferenceResolutionUtils.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ private static CustomerDraft mapToCustomerDraft(
9797
return CustomerDraftBuilder.of()
9898
.email(customer.getEmail())
9999
.password(customer.getPassword())
100+
.authenticationMode(customer.getAuthenticationMode())
100101
.customerNumber(customer.getCustomerNumber())
101102
.key(customer.getKey())
102103
.firstName(customer.getFirstName())

src/test/java/com/commercetools/sync/customers/helpers/CustomerBatchValidatorTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import com.commercetools.api.client.ProjectApiRoot;
1111
import com.commercetools.api.models.common.AddressDraftBuilder;
1212
import com.commercetools.api.models.common.BaseAddress;
13+
import com.commercetools.api.models.customer.AuthenticationMode;
1314
import com.commercetools.api.models.customer.CustomerDraft;
1415
import com.commercetools.api.models.customer.CustomerDraftBuilder;
1516
import com.commercetools.api.models.customer_group.CustomerGroupResourceIdentifierBuilder;
@@ -161,6 +162,23 @@ void validateAndCollectReferencedKeys_WithEmptyDraft_ShouldHaveEmptyResult() {
161162
assertThat(validDrafts).isEmpty();
162163
}
163164

165+
@Test
166+
void
167+
validateAndCollectReferencedKeys_WithCustomerDraftWithEmptyPasswordAndExternalAuth_ShouldBeValid() {
168+
final CustomerDraft customerDraft =
169+
CustomerDraftBuilder.of()
170+
.email("email")
171+
.password(EMPTY)
172+
.authenticationMode(AuthenticationMode.EXTERNAL_AUTH)
173+
.key("key")
174+
.build();
175+
176+
final Set<CustomerDraft> validDrafts = getValidDrafts(singletonList(customerDraft));
177+
178+
assertThat(errorCallBackMessages).hasSize(0);
179+
assertThat(validDrafts).containsExactly(customerDraft);
180+
}
181+
164182
@Test
165183
void validateAndCollectReferencedKeys_WithNullAddressList_ShouldNotHaveValidationError() {
166184
final CustomerDraft customerDraft =

0 commit comments

Comments
 (0)