Skip to content

Commit

Permalink
add tests for node and rnode proxies
Browse files Browse the repository at this point in the history
  • Loading branch information
johrstrom committed May 4, 2021
1 parent 9c28749 commit 7eb59af
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ ARG GID=1000

RUN dnf reinstall -y httpd-tools && \
dnf install -y \
strace lua && \
strace lua python3 && \
dnf clean all && rm -rf /var/cache/dnf/*

RUN groupadd -g $GID $USER && \
Expand Down
6 changes: 6 additions & 0 deletions Dockerfile.test
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ ARG USER=ood
ARG UID=1000
ARG GID=1000

RUN dnf install -y \
python3 && \
dnf clean all && rm -rf /var/cache/dnf/* && \
python3 -m pip \
install flask

RUN groupadd -g $GID $USER && \
useradd -u $UID --create-home --gid $USER $USER

Expand Down
4 changes: 4 additions & 0 deletions spec/e2e/e2e_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ def portal_fixture(file)
"#{File.expand_path('.')}/spec/fixtures/config/ood_portal/#{file}"
end

def extra_fixtures
"#{File.expand_path('.')}/spec/fixtures/extras"
end

def container_exec(cmd)
`#{container_runtime} exec #{test_image_name} #{cmd}`.to_s
end
72 changes: 72 additions & 0 deletions spec/e2e/proxy_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
require 'watir'
require_relative 'e2e_helper'

describe 'Node and Rnode proxies' do

def browser
@browser ||= new_browser
end

before(:all) do
mnts = ["-v", "#{extra_fixtures}:/opt/extras"]
mnts.concat ["-v", "#{portal_fixture('portal_with_proxies.yml')}:/etc/ood/config/ood_portal.yml"]
Rake::Task['test:start_test_container'].execute(mount_args: mnts)

container_exec("/bin/bash -c '/opt/extras/simple_origin_server.py >/tmp/rnode.out 2>&1 &'")
container_exec("/bin/bash -c 'FLASK_PORT=5001 FLASK_BASE_URL=/node/localhost/5001 /opt/extras/simple_origin_server.py >/tmp/node.out 2>&1 &'")
browser_login(browser)
end

after(:all) do
Rake::Task['test:stop_test_container'].execute
browser.close
end

it 'rnode proxies directly to the origin' do
browser.goto "#{ctr_base_url}/rnode/localhost/5000/simple-page"
expect(browser.url).to eq("#{ctr_base_url}/rnode/localhost/5000/simple-page")
expect(browser.div(id: "test-div").present?).to be true
end

it 'rnode redirects to the origin' do
browser.goto "#{ctr_base_url}/rnode/localhost/5000/simple-redirect"
expect(browser.url).to eq("#{ctr_base_url}/rnode/localhost/5000/simple-page")
expect(browser.div(id: "test-div").present?).to be true
end

it 'rnode redirects to the origin when no path is given' do
browser.goto "#{ctr_base_url}/rnode/localhost/5000"
expect(browser.url).to eq("#{ctr_base_url}/rnode/localhost/5000/simple-page")
expect(browser.div(id: "test-div").present?).to be true
end

it 'rnode redirects to the origin when only root is given' do
browser.goto "#{ctr_base_url}/rnode/localhost/5000/"
expect(browser.url).to eq("#{ctr_base_url}/rnode/localhost/5000/simple-page")
expect(browser.div(id: "test-div").present?).to be true
end

it 'node proxies directly to the origin' do
browser.goto "#{ctr_base_url}/node/localhost/5001/simple-page"
expect(browser.url).to eq("#{ctr_base_url}/node/localhost/5001/simple-page")
expect(browser.div(id: "test-div").present?).to be true
end

it 'rnode redirects to the origin' do
browser.goto "#{ctr_base_url}/node/localhost/5001/simple-redirect"
expect(browser.url).to eq("#{ctr_base_url}/node/localhost/5001/simple-page")
expect(browser.div(id: "test-div").present?).to be true
end

it 'node redirects to the origin with nothing extra in the path' do
browser.goto "#{ctr_base_url}/node/localhost/5001"
expect(browser.url).to eq("#{ctr_base_url}/node/localhost/5001/simple-page")
expect(browser.div(id: "test-div").present?).to be true
end

it 'node redirects to the origin when only root is given' do
browser.goto "#{ctr_base_url}/node/localhost/5001/"
expect(browser.url).to eq("#{ctr_base_url}/node/localhost/5001/simple-page")
expect(browser.div(id: "test-div").present?).to be true
end
end
11 changes: 11 additions & 0 deletions spec/fixtures/config/ood_portal/portal_with_proxies.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
#
# Portal configuration
#

listen_addr_port: 8080
servername: localhost
port: 8080

rnode_uri: '/rnode'
node_uri: '/node'
43 changes: 43 additions & 0 deletions spec/fixtures/extras/simple_origin_server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env python3

import os
from flask import Flask, redirect, request, Blueprint, url_for

app = Blueprint('app', 'simple_origin_server_blueprint')

@app.route("/one/two/three/relative-redirect")
def relative_redirect():
return redirect(url_for('app.one_level_down'), code=302)

@app.route("/one/one-level-down")
def one_level_down():
simple_page()

@app.route("/simple-redirect")
def simple_redirect():
return redirect(url_for('app.simple_page'), code=302)

@app.route('/')
def root():
return redirect(url_for('app.simple_page'), code=302)

@app.route("/simple-page")
def simple_page():
return "<html><body><div id='test-div'>A very simple page for testing</div></body></html>"

if __name__ == '__main__':
super_app = Flask(__name__)

if os.environ.get('FLASK_BASE_URL'):
print('app root is ' + os.environ.get('FLASK_BASE_URL'))
super_app.register_blueprint(app, url_prefix=os.environ.get('FLASK_BASE_URL'))
else:
super_app.register_blueprint(app, url_prefix='/')

if os.environ.get('FLASK_PORT'):
port = int(os.environ.get('FLASK_PORT'))
else:
port = 5000

print(super_app.url_map)
super_app.run(host='127.0.0.1', port=port, debug=True)

0 comments on commit 7eb59af

Please sign in to comment.