mirror of
https://github.com/ansible/awx.git
synced 2026-02-20 12:40:06 -03:30
Merge pull request #8877 from jakemcdermott/ws-proto
Support ws or wss proto Reviewed-by: https://github.com/apps/softwarefactory-project-zuul
This commit is contained in:
@@ -44,7 +44,7 @@ describe('useWsJobs hook', () => {
|
|||||||
|
|
||||||
test('should establish websocket connection', async () => {
|
test('should establish websocket connection', async () => {
|
||||||
global.document.cookie = 'csrftoken=abc123';
|
global.document.cookie = 'csrftoken=abc123';
|
||||||
const mockServer = new WS('wss://localhost/websocket/');
|
const mockServer = new WS('ws://localhost/websocket/');
|
||||||
|
|
||||||
const jobs = [{ id: 1 }];
|
const jobs = [{ id: 1 }];
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
@@ -67,7 +67,7 @@ describe('useWsJobs hook', () => {
|
|||||||
|
|
||||||
test('should update job status', async () => {
|
test('should update job status', async () => {
|
||||||
global.document.cookie = 'csrftoken=abc123';
|
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' }];
|
const jobs = [{ id: 1, status: 'running' }];
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
@@ -105,7 +105,7 @@ describe('useWsJobs hook', () => {
|
|||||||
|
|
||||||
test('should fetch new job', async () => {
|
test('should fetch new job', async () => {
|
||||||
global.document.cookie = 'csrftoken=abc123';
|
global.document.cookie = 'csrftoken=abc123';
|
||||||
const mockServer = new WS('wss://localhost/websocket/');
|
const mockServer = new WS('ws://localhost/websocket/');
|
||||||
const jobs = [{ id: 1 }];
|
const jobs = [{ id: 1 }];
|
||||||
const fetch = jest.fn(() => []);
|
const fetch = jest.fn(() => []);
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ describe('useWsInventories hook', () => {
|
|||||||
|
|
||||||
test('should establish websocket connection', async () => {
|
test('should establish websocket connection', async () => {
|
||||||
global.document.cookie = 'csrftoken=abc123';
|
global.document.cookie = 'csrftoken=abc123';
|
||||||
const mockServer = new WS('wss://localhost/websocket/');
|
const mockServer = new WS('ws://localhost/websocket/');
|
||||||
|
|
||||||
const inventories = [{ id: 1 }];
|
const inventories = [{ id: 1 }];
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
@@ -83,7 +83,7 @@ describe('useWsInventories hook', () => {
|
|||||||
|
|
||||||
test('should update inventory sync status', async () => {
|
test('should update inventory sync status', async () => {
|
||||||
global.document.cookie = 'csrftoken=abc123';
|
global.document.cookie = 'csrftoken=abc123';
|
||||||
const mockServer = new WS('wss://localhost/websocket/');
|
const mockServer = new WS('ws://localhost/websocket/');
|
||||||
|
|
||||||
const inventories = [{ id: 1 }];
|
const inventories = [{ id: 1 }];
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
@@ -121,7 +121,7 @@ describe('useWsInventories hook', () => {
|
|||||||
|
|
||||||
test('should fetch fresh inventory after sync runs', async () => {
|
test('should fetch fresh inventory after sync runs', async () => {
|
||||||
global.document.cookie = 'csrftoken=abc123';
|
global.document.cookie = 'csrftoken=abc123';
|
||||||
const mockServer = new WS('wss://localhost/websocket/');
|
const mockServer = new WS('ws://localhost/websocket/');
|
||||||
const inventories = [{ id: 1 }];
|
const inventories = [{ id: 1 }];
|
||||||
const fetchInventories = jest.fn(() => []);
|
const fetchInventories = jest.fn(() => []);
|
||||||
const fetchInventoriesById = jest.fn(() => []);
|
const fetchInventoriesById = jest.fn(() => []);
|
||||||
@@ -152,7 +152,7 @@ describe('useWsInventories hook', () => {
|
|||||||
|
|
||||||
test('should update inventory pending_deletion', async () => {
|
test('should update inventory pending_deletion', async () => {
|
||||||
global.document.cookie = 'csrftoken=abc123';
|
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 }];
|
const inventories = [{ id: 1, pending_deletion: false }];
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
@@ -190,7 +190,7 @@ describe('useWsInventories hook', () => {
|
|||||||
|
|
||||||
test('should refetch inventories after an inventory is deleted', async () => {
|
test('should refetch inventories after an inventory is deleted', async () => {
|
||||||
global.document.cookie = 'csrftoken=abc123';
|
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 inventories = [{ id: 1 }, { id: 2 }];
|
||||||
const fetchInventories = jest.fn(() => []);
|
const fetchInventories = jest.fn(() => []);
|
||||||
const fetchInventoriesById = jest.fn(() => []);
|
const fetchInventoriesById = jest.fn(() => []);
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ describe('useWsInventorySources hook', () => {
|
|||||||
|
|
||||||
test('should establish websocket connection', async () => {
|
test('should establish websocket connection', async () => {
|
||||||
global.document.cookie = 'csrftoken=abc123';
|
global.document.cookie = 'csrftoken=abc123';
|
||||||
const mockServer = new WS('wss://localhost/websocket/');
|
const mockServer = new WS('ws://localhost/websocket/');
|
||||||
|
|
||||||
const sources = [{ id: 1 }];
|
const sources = [{ id: 1 }];
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
@@ -65,7 +65,7 @@ describe('useWsInventorySources hook', () => {
|
|||||||
|
|
||||||
test('should update last job status', async () => {
|
test('should update last job status', async () => {
|
||||||
global.document.cookie = 'csrftoken=abc123';
|
global.document.cookie = 'csrftoken=abc123';
|
||||||
const mockServer = new WS('wss://localhost/websocket/');
|
const mockServer = new WS('ws://localhost/websocket/');
|
||||||
|
|
||||||
const sources = [
|
const sources = [
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -170,7 +170,11 @@ const OutputFooter = styled.div`
|
|||||||
|
|
||||||
let ws;
|
let ws;
|
||||||
function connectJobSocket({ type, id }, onMessage) {
|
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 = () => {
|
ws.onopen = () => {
|
||||||
const xrftoken = `; ${document.cookie}`
|
const xrftoken = `; ${document.cookie}`
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ describe('useWsProjects', () => {
|
|||||||
|
|
||||||
test('should establish websocket connection', async () => {
|
test('should establish websocket connection', async () => {
|
||||||
global.document.cookie = 'csrftoken=abc123';
|
global.document.cookie = 'csrftoken=abc123';
|
||||||
const mockServer = new WS('wss://localhost/websocket/');
|
const mockServer = new WS('ws://localhost/websocket/');
|
||||||
|
|
||||||
const projects = [{ id: 1 }];
|
const projects = [{ id: 1 }];
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
@@ -58,7 +58,7 @@ describe('useWsProjects', () => {
|
|||||||
|
|
||||||
test('should update project status', async () => {
|
test('should update project status', async () => {
|
||||||
global.document.cookie = 'csrftoken=abc123';
|
global.document.cookie = 'csrftoken=abc123';
|
||||||
const mockServer = new WS('wss://localhost/websocket/');
|
const mockServer = new WS('ws://localhost/websocket/');
|
||||||
|
|
||||||
const projects = [
|
const projects = [
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ describe('useWsWorkflowApprovals hook', () => {
|
|||||||
|
|
||||||
test('should establish websocket connection', async () => {
|
test('should establish websocket connection', async () => {
|
||||||
global.document.cookie = 'csrftoken=abc123';
|
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 workflowApprovals = [{ id: 1, status: 'successful' }];
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
@@ -79,7 +79,7 @@ describe('useWsWorkflowApprovals hook', () => {
|
|||||||
|
|
||||||
test('should refetch after new approval job is created', async () => {
|
test('should refetch after new approval job is created', async () => {
|
||||||
global.document.cookie = 'csrftoken=abc123';
|
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 workflowApprovals = [{ id: 1, status: 'successful' }];
|
||||||
const fetchWorkflowApprovals = jest.fn(() => []);
|
const fetchWorkflowApprovals = jest.fn(() => []);
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
@@ -107,7 +107,7 @@ describe('useWsWorkflowApprovals hook', () => {
|
|||||||
|
|
||||||
test('should refetch after approval job in current list is updated', async () => {
|
test('should refetch after approval job in current list is updated', async () => {
|
||||||
global.document.cookie = 'csrftoken=abc123';
|
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 workflowApprovals = [{ id: 1, status: 'pending' }];
|
||||||
const fetchWorkflowApprovals = jest.fn(() => []);
|
const fetchWorkflowApprovals = jest.fn(() => []);
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
@@ -135,7 +135,7 @@ describe('useWsWorkflowApprovals hook', () => {
|
|||||||
|
|
||||||
test('should not refetch when message is not workflow approval', async () => {
|
test('should not refetch when message is not workflow approval', async () => {
|
||||||
global.document.cookie = 'csrftoken=abc123';
|
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 workflowApprovals = [{ id: 1, status: 'successful' }];
|
||||||
const fetchWorkflowApprovals = jest.fn(() => []);
|
const fetchWorkflowApprovals = jest.fn(() => []);
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
|
|||||||
@@ -5,7 +5,11 @@ export default function useWebsocket(subscribeGroups) {
|
|||||||
const ws = useRef(null);
|
const ws = useRef(null);
|
||||||
|
|
||||||
useEffect(function setupSocket() {
|
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 connect = () => {
|
||||||
const xrftoken = `; ${document.cookie}`
|
const xrftoken = `; ${document.cookie}`
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ describe('useWsTemplates hook', () => {
|
|||||||
|
|
||||||
test('should establish websocket connection', async () => {
|
test('should establish websocket connection', async () => {
|
||||||
global.document.cookie = 'csrftoken=abc123';
|
global.document.cookie = 'csrftoken=abc123';
|
||||||
const mockServer = new WS('wss://localhost/websocket/');
|
const mockServer = new WS('ws://localhost/websocket/');
|
||||||
|
|
||||||
const templates = [{ id: 1 }];
|
const templates = [{ id: 1 }];
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
@@ -65,7 +65,7 @@ describe('useWsTemplates hook', () => {
|
|||||||
|
|
||||||
test('should update recent job status', async () => {
|
test('should update recent job status', async () => {
|
||||||
global.document.cookie = 'csrftoken=abc123';
|
global.document.cookie = 'csrftoken=abc123';
|
||||||
const mockServer = new WS('wss://localhost/websocket/');
|
const mockServer = new WS('ws://localhost/websocket/');
|
||||||
|
|
||||||
const templates = [
|
const templates = [
|
||||||
{
|
{
|
||||||
@@ -125,7 +125,7 @@ describe('useWsTemplates hook', () => {
|
|||||||
|
|
||||||
test('should add new job status', async () => {
|
test('should add new job status', async () => {
|
||||||
global.document.cookie = 'csrftoken=abc123';
|
global.document.cookie = 'csrftoken=abc123';
|
||||||
const mockServer = new WS('wss://localhost/websocket/');
|
const mockServer = new WS('ws://localhost/websocket/');
|
||||||
|
|
||||||
const templates = [
|
const templates = [
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user