<commit_before>const otplib = require('otplib')
const config = require('config')

const EC = protractor.ExpectedConditions

describe('/#/basket', () => {
  let successMessage
  let setupInstructions
  let currentPassword
  let initalToken
  let submit

  beforeEach(() => {
    successMessage = element(by.id('2fa-setup-successfully'))
    setupInstructions = element(by.id('2fa-setup-instructions'))
    currentPassword = element(by.id('currentPassword'))
    initalToken = element(by.id('initalToken'))
    submit = element(by.id('setupTwoFactorAuth'))
  })

  describe('as wurstbrot', () => {
    protractor.beforeEach.login({
      email: '<EMAIL>@' + config.get('application.domain'),
      password: '<PASSWORD>!',
      totpSecret: '<KEY>'
    })

    it('should show an success message for 2fa enabled accounts', () => {
      browser.get('/#/privacy-security/two-factor-authentication')

      browser.wait(EC.visibilityOf(successMessage), 5000, '2FA success message didnt show up for an 2fa enabled account in time')
    })
  })

  describe('as amy', () => {
    protractor.beforeEach.login({ email: '<EMAIL>@' + config.get('application.domain'), password: '<PASSWORD>.....................' })

    it('should be possible to setup 2fa for a account without 2fa enabled', async () => {
      browser.get('/#/privacy-security/two-factor-authentication')

      browser.wait(EC.visibilityOf(setupInstructions), 5000, '2FA setup instructions should show up for users without 2fa enabled')

      const secret = await initalToken.getAttribute('data-test-totp-secret');

      currentPassword.sendKeys('<PASSWORD>.....................')
      // initalToken.sendKeys('foobar')
      initalToken.sendKeys(otplib.authenticator.generate(secret))
      submit.click()

      browser.wait(EC.visibilityOf(successMessage), 5000, 'success message didnt show up in time after enabling 2fa for an account')
    })
  })
})<commit_msg>Disable 2fa for amy after setting it up in e2e test<commit_after>const otplib = require('otplib')
const config = require('config')

const EC = protractor.ExpectedConditions

fdescribe('/#/basket', () => {
  let successMessage
  let setupInstructions
  let currentPassword
  let initalToken
  let setupSubmit
  let disableSubmit

  beforeEach(() => {
    successMessage = element(by.id('2fa-setup-successfully'))
    setupInstructions = element(by.id('2fa-setup-instructions'))
    currentPassword = element(by.id('currentPassword'))
    initalToken = element(by.id('initalToken'))
    setupSubmit = element(by.id('setupTwoFactorAuth'))
    disableSubmit = element(by.id('disableTwoFactorAuth'))
  })

  describe('as wurstbrot', () => {
    protractor.beforeEach.login({
      email: '<EMAIL>@' + <EMAIL>('application.<EMAIL>'),
      password: '<PASSWORD>!',
      totpSecret: 'IFTXE3SPOEYVURT2MRYGI52TKJ4HC3KH'
    })

    it('should show an success message for 2fa enabled accounts', () => {
      browser.get('/#/privacy-security/two-factor-authentication')

      browser.wait(EC.visibilityOf(successMessage), 5000, '2FA success message didnt show up for an 2fa enabled account in time')
    })
  })

  describe('as amy', () => {
    protractor.beforeEach.login({ email: '<EMAIL>'), password: '<PASSWORD>.....................' })

    it('should be possible to setup 2fa for a account without 2fa enabled', async () => {
      browser.get('/#/privacy-security/two-factor-authentication')

      browser.wait(EC.visibilityOf(setupInstructions), 5000, '2FA setup instructions should show up for users without 2fa enabled')

      const secret = await initalToken.getAttribute('data-test-totp-secret');

      currentPassword.sendKeys('<PASSWORD>.....................')
      initalToken.sendKeys(otplib.authenticator.generate(secret))
      setupSubmit.click()

      browser.wait(EC.visibilityOf(successMessage), 5000, 'success message didnt show up in time after enabling 2fa for an account')

      currentPassword.sendKeys('<PASSWORD>.....................')
      disableSubmit.click()

      browser.wait(EC.visibilityOf(setupInstructions), 5000, '2FA setup instructions should show up after users disabled their accounts')
    })
  })
})
{'fraction_non_alphanumeric': 0.15815959741193386, 'fraction_numerical': 0.013659237958303379, 'mean_word_length': 3.6636871508379887, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7555621', 'n_tokens_mistral': 1263, 'n_tokens_neox': 1182, 'n_words': 275}