Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(socket): reconnection for websocket replacing in the process #100

Merged
merged 38 commits into from
Feb 14, 2025

Conversation

juancgalvis
Copy link
Contributor

Description

Replace socket when a new socket connection is authenticated, update examples

Category

  • Feature
  • Fix

Checklist

  • The pull request is complete according to the guide of contributing
  • Automated tests are written
  • The documentation is up-to-date
  • the version of the mix.exs was increased
  • The pull request has a descriptive title that describes what has changed, and provides enough context for the changelog

}

private onSocketMessage(event) {
const message = this.serializer.decode(event)

Check notice

Code scanning / CodeQL

Semicolon insertion Note

Avoid automated semicolon insertion (91% of all statements in
the enclosing function
have an explicit semicolon).

Copilot Autofix AI 7 days ago

To fix the problem, we need to add an explicit semicolon at the end of the line const message = this.serializer.decode(event). This change will ensure that the code adheres to the recommended practice of using explicit semicolons and maintains consistency with the rest of the code in the function.

Suggested changeset 1
clients/client-js/src/transport/ws-transport.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/clients/client-js/src/transport/ws-transport.ts b/clients/client-js/src/transport/ws-transport.ts
--- a/clients/client-js/src/transport/ws-transport.ts
+++ b/clients/client-js/src/transport/ws-transport.ts
@@ -117,3 +117,3 @@
     private onSocketMessage(event) {
-        const message = this.serializer.decode(event)
+        const message = this.serializer.decode(event);
         if (!this.isActive && message.event == "AuthOk") {
EOF
@@ -117,3 +117,3 @@
private onSocketMessage(event) {
const message = this.serializer.decode(event)
const message = this.serializer.decode(event);
if (!this.isActive && message.event == "AuthOk") {
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
});
})

Check notice

Code scanning / CodeQL

Semicolon insertion Note test

Avoid automated semicolon insertion (90% of all statements in
the enclosing function
have an explicit semicolon).

Copilot Autofix AI 9 days ago

To fix the problem, we need to add an explicit semicolon at the end of the statement on line 189. This will ensure consistency with the rest of the codebase and prevent any unintended behavior due to JavaScript's automatic semicolon insertion.

  • Locate the statement on line 189 in the file clients/client-js/test/async-client.test.ts.
  • Add a semicolon at the end of the statement to make it explicit.
Suggested changeset 1
clients/client-js/test/async-client.test.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/clients/client-js/test/async-client.test.ts b/clients/client-js/test/async-client.test.ts
--- a/clients/client-js/test/async-client.test.ts
+++ b/clients/client-js/test/async-client.test.ts
@@ -188,3 +188,3 @@
         });
-    })
+    });
 
EOF
@@ -188,3 +188,3 @@
});
})
});

Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
import { ChannelMessage } from "../../src/channel-message";
import { SseTransport } from "../../src/transport";
import "fast-text-encoding"
import { managedObservable, promiseFromObservable, timeout, waitFor } from '../utils/types.utils';

Check notice

Code scanning / CodeQL

Unused variable, import, function or class Note test

Unused imports timeout, waitFor.

Copilot Autofix AI 7 days ago

To fix the problem, we need to remove the unused imports timeout and waitFor from the import statement on line 9. This will clean up the code and eliminate any confusion regarding unused imports.

  • Remove timeout and waitFor from the import statement on line 9.
  • Ensure that the remaining imports in the statement are still correctly used in the code.
Suggested changeset 1
clients/client-js/test/transport/sse-transport.test.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/clients/client-js/test/transport/sse-transport.test.ts b/clients/client-js/test/transport/sse-transport.test.ts
--- a/clients/client-js/test/transport/sse-transport.test.ts
+++ b/clients/client-js/test/transport/sse-transport.test.ts
@@ -8,3 +8,3 @@
 import "fast-text-encoding"
-import { managedObservable, promiseFromObservable, timeout, waitFor } from '../utils/types.utils';
+import { managedObservable, promiseFromObservable } from '../utils/types.utils';
 
EOF
@@ -8,3 +8,3 @@
import "fast-text-encoding"
import { managedObservable, promiseFromObservable, timeout, waitFor } from '../utils/types.utils';
import { managedObservable, promiseFromObservable } from '../utils/types.utils';

Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
let config: AsyncConfig = {
socket_url: "ws://localhost:3000",
channel_ref: "channel-1",
channel_secret: "token-1",

Check failure

Code scanning / CodeQL

Hard-coded credentials Critical test

The hard-coded value "token-1" is used as
authorization header
.
let config: AsyncConfig = {
socket_url: "ws://localhost:3000",
channel_ref: "channel-2",
channel_secret: "token-2",

Check failure

Code scanning / CodeQL

Hard-coded credentials Critical test

The hard-coded value "token-2" is used as
authorization header
.
let config: AsyncConfig = {
socket_url: "ws://localhost:3000",
channel_ref: "channel-3",
channel_secret: "token-3",

Check failure

Code scanning / CodeQL

Hard-coded credentials Critical test

The hard-coded value "token-3" is used as
authorization header
.
managed = managedObservable();
mockServer = new Server(`${config.socket_url}/ext/socket`);
client = WsTransport.create(config, managed.onMessage, managed.onError, WebSocket);
})

Check notice

Code scanning / CodeQL

Semicolon insertion Note test

Avoid automated semicolon insertion (91% of all statements in
the enclosing function
have an explicit semicolon).

Copilot Autofix AI 7 days ago

To fix the problem, we need to add an explicit semicolon at the end of the statement on line 30. This will ensure consistency with the rest of the code and prevent any potential issues caused by automatic semicolon insertion.

  • Add a semicolon at the end of the statement on line 30 in the file clients/client-js/test/transport/ws-transport.test.ts.
Suggested changeset 1
clients/client-js/test/transport/ws-transport.test.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/clients/client-js/test/transport/ws-transport.test.ts b/clients/client-js/test/transport/ws-transport.test.ts
--- a/clients/client-js/test/transport/ws-transport.test.ts
+++ b/clients/client-js/test/transport/ws-transport.test.ts
@@ -29,3 +29,3 @@
         client = WsTransport.create(config, managed.onMessage, managed.onError, WebSocket) as WsTransport;
-    })
+    });
 
EOF
@@ -29,3 +29,3 @@
client = WsTransport.create(config, managed.onMessage, managed.onError, WebSocket) as WsTransport;
})
});

Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
} else if (new String(data).startsWith('Auth::')) {
// @ts-ignore
console.log("server. invalid credentials");
mockServer.close({ code: 4403, reason: "Invalid auth", wasClean: true })

Check notice

Code scanning / CodeQL

Semicolon insertion Note test

Avoid automated semicolon insertion (90% of all statements in
the enclosing function
have an explicit semicolon).

Copilot Autofix AI 7 days ago

To fix the problem, we need to add an explicit semicolon at the end of the mockServer.close statement. This will ensure that the statement is correctly terminated and prevent any potential issues related to automatic semicolon insertion.

  • Locate the mockServer.close statement on line 276 in the file clients/client-js/test/transport/ws-transport.test.ts.
  • Add a semicolon at the end of the statement to explicitly terminate it.
Suggested changeset 1
clients/client-js/test/transport/ws-transport.test.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/clients/client-js/test/transport/ws-transport.test.ts b/clients/client-js/test/transport/ws-transport.test.ts
--- a/clients/client-js/test/transport/ws-transport.test.ts
+++ b/clients/client-js/test/transport/ws-transport.test.ts
@@ -275,3 +275,3 @@
                         console.log("server. invalid credentials");
-                        mockServer.close({ code: 4403, reason: "Invalid auth", wasClean: true })
+                        mockServer.close({ code: 4403, reason: "Invalid auth", wasClean: true });
                     }
EOF
@@ -275,3 +275,3 @@
console.log("server. invalid credentials");
mockServer.close({ code: 4403, reason: "Invalid auth", wasClean: true })
mockServer.close({ code: 4403, reason: "Invalid auth", wasClean: true });
}
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
const result = await waitFor(connected);
assert.equal(result, true);
return client.getDecoder();
}

Check notice

Code scanning / CodeQL

Semicolon insertion Note test

Avoid automated semicolon insertion (90% of all statements in
the enclosing function
have an explicit semicolon).
res.write(`data: ${event}\n\n`);
}

console.log(`SSEMockServer: ${req.method} ${req.url}`);

Check warning

Code scanning / CodeQL

Log injection Medium test

Log entry depends on a
user-provided value
.

Copilot Autofix AI 9 days ago

To fix the problem, we need to sanitize the user input before logging it. Specifically, we should remove any newline characters from req.url and req.method to prevent log injection attacks. This can be done using the String.prototype.replace method to strip out any newline characters.

We will modify the logging statement on line 13 to sanitize req.method and req.url before logging them. This ensures that any malicious input is neutralized before it can affect the log entries.

Suggested changeset 1
clients/client-js/test/utils/sse-mock-server.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/clients/client-js/test/utils/sse-mock-server.ts b/clients/client-js/test/utils/sse-mock-server.ts
--- a/clients/client-js/test/utils/sse-mock-server.ts
+++ b/clients/client-js/test/utils/sse-mock-server.ts
@@ -12,3 +12,5 @@
 
-        console.log(`SSEMockServer: ${req.method} ${req.url}`);
+        const sanitizedMethod = req.method?.replace(/\n|\r/g, "");
+        const sanitizedUrl = req.url?.replace(/\n|\r/g, "");
+        console.log(`SSEMockServer: ${sanitizedMethod} ${sanitizedUrl}`);
         const mockResponse = SSEMockServer.getMock(req.url!);
EOF
@@ -12,3 +12,5 @@

console.log(`SSEMockServer: ${req.method} ${req.url}`);
const sanitizedMethod = req.method?.replace(/\n|\r/g, "");
const sanitizedUrl = req.url?.replace(/\n|\r/g, "");
console.log(`SSEMockServer: ${sanitizedMethod} ${sanitizedUrl}`);
const mockResponse = SSEMockServer.getMock(req.url!);
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
@@ -4,6 +4,8 @@
import { Subject } from 'rxjs';
import { Message } from '../models/message.inteface';
import { environment } from '../environments/environment';
import { SettingsService } from './settings.service';
import { U } from '@angular/cdk/keycodes';

Check notice

Code scanning / CodeQL

Unused variable, import, function or class Note

Unused import U.

Copilot Autofix AI 9 days ago

To fix the problem, we need to remove the unused import statement from the file. This will make the code cleaner and eliminate any confusion about the usage of U. The change should be made in the file examples/front-async-angular/src/app/services/async-client.service.ts by removing the line that imports U from @angular/cdk/keycodes.

Suggested changeset 1
examples/front-async-angular/src/app/services/async-client.service.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/examples/front-async-angular/src/app/services/async-client.service.ts b/examples/front-async-angular/src/app/services/async-client.service.ts
--- a/examples/front-async-angular/src/app/services/async-client.service.ts
+++ b/examples/front-async-angular/src/app/services/async-client.service.ts
@@ -7,3 +7,3 @@
 import { SettingsService } from './settings.service';
-import { U } from '@angular/cdk/keycodes';
+
 
EOF
@@ -7,3 +7,3 @@
import { SettingsService } from './settings.service';
import { U } from '@angular/cdk/keycodes';


Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
@github-advanced-security
Copy link

This pull request sets up GitHub code scanning for this repository. Once the scans have completed and the checks have passed, the analysis results for this pull request branch will appear on this overview. Once you merge this pull request, the 'Security' tab will show more code scanning analysis results (for example, for the default branch). Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results. For more information about GitHub code scanning, check out the documentation.

@juancgalvis juancgalvis reopened this Feb 14, 2025
@santitigaga santitigaga merged commit a0ad78b into master Feb 14, 2025
8 of 9 checks passed
@juancgalvis juancgalvis deleted the fix/socket-reconnection branch February 14, 2025 16:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants