<commit_before>var selftest = require('../selftest.js');
var utils = require('../test-utils.js');
var Sandbox = selftest.Sandbox;
var AUTHTIMEOUT = 5;

var loggedInError = selftest.markStack(function(run) {
  run.waitSecs(AUTHTIMEOUT);
  run.matchErr("You must be logged in to claim sites.");
  run.expectExit(1);
});

var waitAndError = selftest.markStack(function(run, errmsg) {
  run.waitSecs(AUTHTIMEOUT);
  run.matchErr(errmsg);
  run.expectExit(1);
});

selftest.define("claim", ['net'], function () {
  var s = new Sandbox;

  // Can't claim sites while logged out.
  // Nonexistent site.
  var run = s.run('claim', utils.randomAppName(20));
  loggedInError(run);

  // Existing site.
  run = s.run('claim', 'mother-test');
  loggedInError(run);

  // Claim will not work on non-legacy sites.
  // belongs to me.
  utils.login(s, "test", "testtest");
  var appName = utils.createAndDeployApp(s);
  run = s.run('claim', appName);
  waitAndError(run, "That site already belongs to you.");

  // belongs to not me.
  utils.logout(s);
  utils.login(s, "testtest", "testtest");
  run = s.run('claim', appName);
  waitAndError(run, "Sorry, that site belongs to someone else.");

  // belongs to not me, but I am authorized.
  utils.logout(s);
  utils.login(s, "test", "testtest");
  run = s.run('authorized', appName, '--add', 'testtest');
  run.waitSecs(5);
  run.expectExit(0);
  utils.logout(s);
  utils.login(s, "testtest", "testtest");
  run = s.run('claim', appName);
  waitAndError(run, "That site already belongs to you.");

  utils.cleanUpApp(s, appName);

  // Legacy sites.
  var sLegacy = new Sandbox({
    // Include a warehouse argument so that we can deploy apps with
    // --release arguments.
    warehouse: {
      v1: { tools: 'tool1', latest: true }
    }
  });

  // legacy w/pwd.
  var pwd = utils.randomString(10);
  var legacyApp = utils.createAndDeployLegacyApp(sLegacy, pwd);

  run = s.run('claim', legacyApp);
  run.waitSecs(5);
  run.matchErr('Password:');
  run.write('<PASSWORD>');
  run.waitSecs(5);
  run.matchErr("Couldn't claim site:");
  run.expectExit(1);

  run = s.run('claim', legacyApp);
  run.waitSecs(5);
  run.matchErr('Password:');
  run.write(pwd+"\n");
  run.match("successfully transferred to your account");
  run.expectExit(0);

  utils.cleanUpApp(s, legacyApp);

  // legacy w/o pwd.
  legacyApp = utils.createAndDeployLegacyApp(sLegacy);

  run = s.run('claim', legacyApp);
  run.waitSecs(5);
  run.match("successfully transferred to your account");
  run.expectExit(0);

  // No site deployed.
  run = s.run('claim', utils.randomAppName(20));
  waitAndError(run, "There isn't a site deployed at that address.");

  utils.cleanUpApp(s, legacyApp);
});<commit_msg>Bump timeouts on 'meteor claim' tests<commit_after>var selftest = require('../selftest.js');
var utils = require('../test-utils.js');
var Sandbox = selftest.Sandbox;
var AUTHTIMEOUT = 15;

var loggedInError = selftest.markStack(function(run) {
  run.waitSecs(AUTHTIMEOUT);
  run.matchErr("You must be logged in to claim sites.");
  run.expectExit(1);
});

var waitAndError = selftest.markStack(function(run, errmsg) {
  run.waitSecs(AUTHTIMEOUT);
  run.matchErr(errmsg);
  run.expectExit(1);
});

selftest.define("claim", ['net'], function () {
  var s = new Sandbox;

  // Can't claim sites while logged out.
  // Nonexistent site.
  var run = s.run('claim', utils.randomAppName(20));
  loggedInError(run);

  // Existing site.
  run = s.run('claim', 'mother-test');
  loggedInError(run);

  // Claim will not work on non-legacy sites.
  // belongs to me.
  utils.login(s, "test", "testtest");
  var appName = utils.createAndDeployApp(s);
  run = s.run('claim', appName);
  waitAndError(run, "That site already belongs to you.");

  // belongs to not me.
  utils.logout(s);
  utils.login(s, "testtest", "testtest");
  run = s.run('claim', appName);
  waitAndError(run, "Sorry, that site belongs to someone else.");

  // belongs to not me, but I am authorized.
  utils.logout(s);
  utils.login(s, "test", "testtest");
  run = s.run('authorized', appName, '--add', 'testtest');
  run.waitSecs(5);
  run.expectExit(0);
  utils.logout(s);
  utils.login(s, "testtest", "testtest");
  run = s.run('claim', appName);
  waitAndError(run, "That site already belongs to you.");

  utils.cleanUpApp(s, appName);

  // Legacy sites.
  var sLegacy = new Sandbox({
    // Include a warehouse argument so that we can deploy apps with
    // --release arguments.
    warehouse: {
      v1: { tools: 'tool1', latest: true }
    }
  });

  // legacy w/pwd.
  var pwd = utils.randomString(10);
  var legacyApp = utils.createAndDeployLegacyApp(sLegacy, pwd);

  run = s.run('claim', legacyApp);
  run.waitSecs(15);
  run.matchErr('Password: ');
  run.write('<PASSWORD>');
  run.waitSecs(15);
  run.matchErr("Couldn't claim site:");
  run.expectExit(1);

  run = s.run('claim', legacyApp);
  run.waitSecs(15);
  run.matchErr('Password:');
  run.write(pwd+"\n");
  run.waitSecs(15);
  run.match("successfully transferred to your account");
  run.expectExit(0);

  utils.cleanUpApp(s, legacyApp);

  // legacy w/o pwd.
  legacyApp = utils.createAndDeployLegacyApp(sLegacy);

  run = s.run('claim', legacyApp);
  run.waitSecs(15);
  run.match("successfully transferred to your account");
  run.expectExit(0);

  // No site deployed.
  run = s.run('claim', utils.randomAppName(20));
  waitAndError(run, "There isn't a site deployed at that address.");

  utils.cleanUpApp(s, legacyApp);
});
{'fraction_non_alphanumeric': 0.16958424507658643, 'fraction_numerical': 0.008570386579139314, 'mean_word_length': 3.849690539345712, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '3787130', 'n_tokens_mistral': 1977, 'n_tokens_neox': 1963, 'n_words': 464}