Skip to content

Commit

Permalink
Merge pull request #8877 from jakemcdermott/ws-proto
Browse files Browse the repository at this point in the history
  • Loading branch information
softwarefactory-project-zuul[bot] authored Dec 15, 2020
2 parents 44df906 + 2cd9a05 commit 3ae6ea9
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 21 deletions.
6 changes: 3 additions & 3 deletions awx/ui_next/src/components/JobList/useWsJobs.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe('useWsJobs hook', () => {

test('should establish websocket connection', async () => {
global.document.cookie = 'csrftoken=abc123';
const mockServer = new WS('wss://localhost/websocket/');
const mockServer = new WS('ws://localhost/websocket/');

const jobs = [{ id: 1 }];
await act(async () => {
Expand All @@ -67,7 +67,7 @@ describe('useWsJobs hook', () => {

test('should update job status', async () => {
global.document.cookie = 'csrftoken=abc123';
const mockServer = new WS('wss://localhost/websocket/');
const mockServer = new WS('ws://localhost/websocket/');

const jobs = [{ id: 1, status: 'running' }];
await act(async () => {
Expand Down Expand Up @@ -105,7 +105,7 @@ describe('useWsJobs hook', () => {

test('should fetch new job', async () => {
global.document.cookie = 'csrftoken=abc123';
const mockServer = new WS('wss://localhost/websocket/');
const mockServer = new WS('ws://localhost/websocket/');
const jobs = [{ id: 1 }];
const fetch = jest.fn(() => []);
await act(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe('useWsInventories hook', () => {

test('should establish websocket connection', async () => {
global.document.cookie = 'csrftoken=abc123';
const mockServer = new WS('wss://localhost/websocket/');
const mockServer = new WS('ws://localhost/websocket/');

const inventories = [{ id: 1 }];
await act(async () => {
Expand All @@ -83,7 +83,7 @@ describe('useWsInventories hook', () => {

test('should update inventory sync status', async () => {
global.document.cookie = 'csrftoken=abc123';
const mockServer = new WS('wss://localhost/websocket/');
const mockServer = new WS('ws://localhost/websocket/');

const inventories = [{ id: 1 }];
await act(async () => {
Expand Down Expand Up @@ -121,7 +121,7 @@ describe('useWsInventories hook', () => {

test('should fetch fresh inventory after sync runs', async () => {
global.document.cookie = 'csrftoken=abc123';
const mockServer = new WS('wss://localhost/websocket/');
const mockServer = new WS('ws://localhost/websocket/');
const inventories = [{ id: 1 }];
const fetchInventories = jest.fn(() => []);
const fetchInventoriesById = jest.fn(() => []);
Expand Down Expand Up @@ -152,7 +152,7 @@ describe('useWsInventories hook', () => {

test('should update inventory pending_deletion', async () => {
global.document.cookie = 'csrftoken=abc123';
const mockServer = new WS('wss://localhost/websocket/');
const mockServer = new WS('ws://localhost/websocket/');

const inventories = [{ id: 1, pending_deletion: false }];
await act(async () => {
Expand Down Expand Up @@ -190,7 +190,7 @@ describe('useWsInventories hook', () => {

test('should refetch inventories after an inventory is deleted', async () => {
global.document.cookie = 'csrftoken=abc123';
const mockServer = new WS('wss://localhost/websocket/');
const mockServer = new WS('ws://localhost/websocket/');
const inventories = [{ id: 1 }, { id: 2 }];
const fetchInventories = jest.fn(() => []);
const fetchInventoriesById = jest.fn(() => []);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe('useWsInventorySources hook', () => {

test('should establish websocket connection', async () => {
global.document.cookie = 'csrftoken=abc123';
const mockServer = new WS('wss://localhost/websocket/');
const mockServer = new WS('ws://localhost/websocket/');

const sources = [{ id: 1 }];
await act(async () => {
Expand All @@ -65,7 +65,7 @@ describe('useWsInventorySources hook', () => {

test('should update last job status', async () => {
global.document.cookie = 'csrftoken=abc123';
const mockServer = new WS('wss://localhost/websocket/');
const mockServer = new WS('ws://localhost/websocket/');

const sources = [
{
Expand Down
6 changes: 5 additions & 1 deletion awx/ui_next/src/screens/Job/JobOutput/JobOutput.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,11 @@ const OutputFooter = styled.div`

let ws;
function connectJobSocket({ type, id }, onMessage) {
ws = new WebSocket(`wss://${window.location.host}/websocket/`);
ws = new WebSocket(
`${window.location.protocol === 'http:' ? 'ws:' : 'wss:'}//${
window.location.host
}/websocket/`
);

ws.onopen = () => {
const xrftoken = `; ${document.cookie}`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('useWsProjects', () => {

test('should establish websocket connection', async () => {
global.document.cookie = 'csrftoken=abc123';
const mockServer = new WS('wss://localhost/websocket/');
const mockServer = new WS('ws://localhost/websocket/');

const projects = [{ id: 1 }];
await act(async () => {
Expand All @@ -58,7 +58,7 @@ describe('useWsProjects', () => {

test('should update project status', async () => {
global.document.cookie = 'csrftoken=abc123';
const mockServer = new WS('wss://localhost/websocket/');
const mockServer = new WS('ws://localhost/websocket/');

const projects = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe('useWsWorkflowApprovals hook', () => {

test('should establish websocket connection', async () => {
global.document.cookie = 'csrftoken=abc123';
const mockServer = new WS('wss://localhost/websocket/');
const mockServer = new WS('ws://localhost/websocket/');

const workflowApprovals = [{ id: 1, status: 'successful' }];
await act(async () => {
Expand All @@ -79,7 +79,7 @@ describe('useWsWorkflowApprovals hook', () => {

test('should refetch after new approval job is created', async () => {
global.document.cookie = 'csrftoken=abc123';
const mockServer = new WS('wss://localhost/websocket/');
const mockServer = new WS('ws://localhost/websocket/');
const workflowApprovals = [{ id: 1, status: 'successful' }];
const fetchWorkflowApprovals = jest.fn(() => []);
await act(async () => {
Expand Down Expand Up @@ -107,7 +107,7 @@ describe('useWsWorkflowApprovals hook', () => {

test('should refetch after approval job in current list is updated', async () => {
global.document.cookie = 'csrftoken=abc123';
const mockServer = new WS('wss://localhost/websocket/');
const mockServer = new WS('ws://localhost/websocket/');
const workflowApprovals = [{ id: 1, status: 'pending' }];
const fetchWorkflowApprovals = jest.fn(() => []);
await act(async () => {
Expand Down Expand Up @@ -135,7 +135,7 @@ describe('useWsWorkflowApprovals hook', () => {

test('should not refetch when message is not workflow approval', async () => {
global.document.cookie = 'csrftoken=abc123';
const mockServer = new WS('wss://localhost/websocket/');
const mockServer = new WS('ws://localhost/websocket/');
const workflowApprovals = [{ id: 1, status: 'successful' }];
const fetchWorkflowApprovals = jest.fn(() => []);
await act(async () => {
Expand Down
6 changes: 5 additions & 1 deletion awx/ui_next/src/util/useWebsocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ export default function useWebsocket(subscribeGroups) {
const ws = useRef(null);

useEffect(function setupSocket() {
ws.current = new WebSocket(`wss://${window.location.host}/websocket/`);
ws.current = new WebSocket(
`${window.location.protocol === 'http:' ? 'ws:' : 'wss:'}//${
window.location.host
}/websocket/`
);

const connect = () => {
const xrftoken = `; ${document.cookie}`
Expand Down
6 changes: 3 additions & 3 deletions awx/ui_next/src/util/useWsTemplates.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe('useWsTemplates hook', () => {

test('should establish websocket connection', async () => {
global.document.cookie = 'csrftoken=abc123';
const mockServer = new WS('wss://localhost/websocket/');
const mockServer = new WS('ws://localhost/websocket/');

const templates = [{ id: 1 }];
await act(async () => {
Expand All @@ -65,7 +65,7 @@ describe('useWsTemplates hook', () => {

test('should update recent job status', async () => {
global.document.cookie = 'csrftoken=abc123';
const mockServer = new WS('wss://localhost/websocket/');
const mockServer = new WS('ws://localhost/websocket/');

const templates = [
{
Expand Down Expand Up @@ -125,7 +125,7 @@ describe('useWsTemplates hook', () => {

test('should add new job status', async () => {
global.document.cookie = 'csrftoken=abc123';
const mockServer = new WS('wss://localhost/websocket/');
const mockServer = new WS('ws://localhost/websocket/');

const templates = [
{
Expand Down

0 comments on commit 3ae6ea9

Please sign in to comment.