Key generation and loading the key into to the session happens in the login hook (OCA\Encryption\Hooks::login). If no key exists we first generate a new one. At this point the key should already exists because the first login happens in setUpBeforeClass(). But even if no key exists this shouldn't be a problem, as described above.