@@ -96,6 +96,81 @@ public void testConsumeLinkCode() throws Exception {
9696 assertNotNull (process .checkOrWaitForEvent (ProcessState .PROCESS_STATE .STOPPED ));
9797 }
9898
99+ /**
100+ * success without existing user - link code with equal signs removed
101+ *
102+ * @throws Exception
103+ */
104+ @ Test
105+ public void testConsumeLinkCodeWithoutEqualSigns () throws Exception {
106+ String [] args = {"../" };
107+
108+ TestingProcessManager .TestingProcess process = TestingProcessManager .start (args );
109+ assertNotNull (process .checkOrWaitForEvent (ProcessState .PROCESS_STATE .STARTED ));
110+
111+ if (StorageLayer .getStorage (process .getProcess ()).getType () != STORAGE_TYPE .SQL ) {
112+ return ;
113+ }
114+
115+ PasswordlessStorage storage = (PasswordlessStorage ) StorageLayer .getStorage (process .getProcess ());
116+
117+ Passwordless .CreateCodeResponse createCodeResponse = Passwordless .createCode (process .getProcess (), EMAIL , null ,
118+ null , null );
119+ assertNotNull (createCodeResponse );
120+
121+ assert (!createCodeResponse .deviceIdHash .contains ("=" ));
122+ assert (!createCodeResponse .linkCode .contains ("=" ));
123+
124+ long consumeStart = System .currentTimeMillis ();
125+ Passwordless .ConsumeCodeResponse consumeCodeResponse = Passwordless .consumeCode (process .getProcess (), null ,
126+ createCodeResponse .deviceIdHash , null , createCodeResponse .linkCode );
127+
128+ assertNotNull (consumeCodeResponse );
129+ checkUserWithConsumeResponse (storage , consumeCodeResponse , EMAIL , null , consumeStart );
130+
131+ PasswordlessDevice [] devices = storage .getDevicesByEmail (new TenantIdentifier (null , null , null ), EMAIL );
132+ assertEquals (0 , devices .length );
133+
134+ process .kill ();
135+ assertNotNull (process .checkOrWaitForEvent (ProcessState .PROCESS_STATE .STOPPED ));
136+ }
137+
138+ /**
139+ * success without existing user - link code with equal signs (padding)
140+ *
141+ * @throws Exception
142+ */
143+ @ Test
144+ public void testConsumeLinkCodeWithEqualSigns () throws Exception {
145+ String [] args = {"../" };
146+
147+ TestingProcessManager .TestingProcess process = TestingProcessManager .start (args );
148+ assertNotNull (process .checkOrWaitForEvent (ProcessState .PROCESS_STATE .STARTED ));
149+
150+ if (StorageLayer .getStorage (process .getProcess ()).getType () != STORAGE_TYPE .SQL ) {
151+ return ;
152+ }
153+
154+ PasswordlessStorage storage = (PasswordlessStorage ) StorageLayer .getStorage (process .getProcess ());
155+
156+ Passwordless .CreateCodeResponse createCodeResponse = Passwordless .createCode (process .getProcess (), EMAIL , null ,
157+ null , null );
158+ assertNotNull (createCodeResponse );
159+
160+ long consumeStart = System .currentTimeMillis ();
161+ Passwordless .ConsumeCodeResponse consumeCodeResponse = Passwordless .consumeCode (process .getProcess (), null ,
162+ createCodeResponse .deviceIdHash + "=" , null , createCodeResponse .linkCode + "=" );
163+
164+ assertNotNull (consumeCodeResponse );
165+ checkUserWithConsumeResponse (storage , consumeCodeResponse , EMAIL , null , consumeStart );
166+
167+ PasswordlessDevice [] devices = storage .getDevicesByEmail (new TenantIdentifier (null , null , null ), EMAIL );
168+ assertEquals (0 , devices .length );
169+
170+ process .kill ();
171+ assertNotNull (process .checkOrWaitForEvent (ProcessState .PROCESS_STATE .STOPPED ));
172+ }
173+
99174 /**
100175 * Success without existing user - input code
101176 *
0 commit comments