Skip to content

Commit a23ebd8

Browse files
committed
Add validation for pmId and property name
1 parent 3507599 commit a23ebd8

File tree

1 file changed

+51
-14
lines changed
  • Assets/ConsentManagementProvider/Scripts/facade

1 file changed

+51
-14
lines changed

Assets/ConsentManagementProvider/Scripts/facade/CMP.cs

Lines changed: 51 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,11 @@ public void Initialize(
4545
CAMPAIGN_ENV campaignsEnvironment,
4646
long messageTimeoutInSeconds = 3)
4747
{
48-
if(!IsSpCampaignsValid(spCampaigns))
49-
{
48+
if (!IsSpCampaignsValid(spCampaigns))
49+
return;
50+
51+
if (!IsPropertyNameValid(ref propertyName))
5052
return;
51-
}
5253

5354
foreach (SpCampaign sp in spCampaigns)
5455
{
@@ -61,14 +62,12 @@ public void Initialize(
6162
}
6263
}
6364

64-
propertyName = propertyName.Trim();
65-
6665
CreateBroadcastExecutorGameObject();
6766

6867
ConcreteInstance.Initialize(
69-
accountId: accountId,
70-
propertyId: propertyId,
71-
propertyName: propertyName,
68+
accountId: accountId,
69+
propertyId: propertyId,
70+
propertyName: propertyName,
7271
language: language,
7372
spCampaigns: spCampaigns,
7473
campaignsEnvironment: campaignsEnvironment,
@@ -82,10 +81,25 @@ public void Initialize(
8281
public void LoadPrivacyManager(
8382
CAMPAIGN_TYPE campaignType,
8483
string pmId,
85-
PRIVACY_MANAGER_TAB tab) => ConcreteInstance.LoadPrivacyManager(
86-
campaignType: campaignType,
87-
pmId: pmId,
88-
tab: tab);
84+
PRIVACY_MANAGER_TAB tab)
85+
{
86+
if (!IsCampaignSetUp(campaignType))
87+
{
88+
CmpDebugUtil.LogError($"Campaign {campaignType} was not setup properly. Aborting...");
89+
return;
90+
}
91+
92+
if (string.IsNullOrEmpty(pmId))
93+
{
94+
CmpDebugUtil.LogError($"pmID is null or empty for campaign {campaignType}. Aborting...");
95+
return;
96+
}
97+
98+
ConcreteInstance.LoadPrivacyManager(
99+
campaignType: campaignType,
100+
pmId: pmId,
101+
tab: tab);
102+
}
89103

90104
public void CustomConsentGDPR(
91105
string[] vendors,
@@ -124,14 +138,37 @@ private void CreateBroadcastExecutorGameObject()
124138
private bool IsSpCampaignsValid(List<SpCampaign> spCampaigns)
125139
{
126140
//check if there more than 0 campaign
127-
if (spCampaigns.Count == 0)
141+
if (spCampaigns is null || spCampaigns.Count == 0)
128142
{
129-
Debug.LogError("You should add at least one SpCampaign to use CMP! Aborting...");
143+
CmpDebugUtil.LogError("You should add at least one SpCampaign to use CMP! Aborting...");
130144
return false;
131145
}
132146

133147
return true;
134148
}
149+
150+
private bool IsPropertyNameValid(ref string propertyName)
151+
{
152+
if (string.IsNullOrEmpty(propertyName) || string.IsNullOrWhiteSpace(propertyName))
153+
{
154+
CmpDebugUtil.LogError("Property Name can`t be null or empty! Aborting...");
155+
return false;
156+
}
157+
propertyName = propertyName.Trim();
158+
return true;
159+
}
160+
161+
private bool IsCampaignSetUp(CAMPAIGN_TYPE campaignType)
162+
{
163+
switch (campaignType)
164+
{
165+
case CAMPAIGN_TYPE.GDPR: return UseGDPR;
166+
case CAMPAIGN_TYPE.CCPA: return UseCCPA;
167+
case CAMPAIGN_TYPE.USNAT: return UseUSNAT;
168+
case CAMPAIGN_TYPE.IOS14: return UseIOS14;
169+
default: return false;
170+
}
171+
}
135172
#endregion
136173
}
137174
}

0 commit comments

Comments
 (0)