From b0e4555a8699deeb0a6624b198717c806769636a Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Wed, 17 May 2017 19:24:43 +0800 Subject: [PATCH] Allow Basic Authentication to be set in smoke test. --- lib/tasks/smoke_test.rake | 16 +++++++++++++--- spec/phantom_js/smoke_test.js | 9 +++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/lib/tasks/smoke_test.rake b/lib/tasks/smoke_test.rake index 890eb128ad8..cb3974cba9d 100644 --- a/lib/tasks/smoke_test.rake +++ b/lib/tasks/smoke_test.rake @@ -15,9 +15,19 @@ task "smoke:test" do require 'open-uri' require 'net/http' - res = Net::HTTP.get_response(URI.parse(url)) - if res.code != "200" - raise "TRIVIAL GET FAILED WITH #{res.code}" + uri = URI(url) + request = Net::HTTP::Get.new(uri) + + if ENV["AUTH_USER"] && ENV["AUTH_PASSWORD"] + request.basic_auth(ENV['AUTH_USER'], ENV['AUTH_PASSWORD']) + end + + response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') do |http| + http.request(request) + end + + if response.code != "200" + raise "TRIVIAL GET FAILED WITH #{response.code}" end results = "" diff --git a/spec/phantom_js/smoke_test.js b/spec/phantom_js/smoke_test.js index 4e55d527251..688383a021c 100644 --- a/spec/phantom_js/smoke_test.js +++ b/spec/phantom_js/smoke_test.js @@ -12,6 +12,11 @@ if (system.args.length !== 2) { var TIMEOUT = 25000; var page = require("webpage").create(); +if (system.env["AUTH_USER"] && system.env["AUTH_PASSWORD"]) { + page.settings.userName = system.env["AUTH_USER"]; + page.settings.password = system.env["AUTH_PASSWORD"]; +} + page.viewportSize = { width: 1366, height: 768 @@ -139,6 +144,10 @@ var runTests = function() { return $(".login-button").text().trim() === "Log In"; }); + execAsync("go to latest page", 500, function(){ + window.location = "/latest"; + }); + test("at least one topic shows up", function() { return $(".topic-list tbody tr").length; });