From fa452445b9ef67d8848b42f73e9911afa7bd69ee Mon Sep 17 00:00:00 2001 From: mleku Date: Thu, 23 Oct 2025 15:31:38 +0100 Subject: [PATCH] Enhance relay management by ensuring URLs are processed with 'wss://' prefix and trailing slashes. Update README.md with detailed testing instructions for extension functionality. --- README.md | 106 ++++++++++++++++++ .../relays/relays.component.html | 2 +- .../edit-identity/relays/relays.component.ts | 16 ++- .../common/src/lib/pipes/visual-relay.pipe.ts | 2 +- .../relays/relays.component.html | 2 +- .../edit-identity/relays/relays.component.ts | 16 ++- 6 files changed, 139 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 1ed3212..5051737 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,112 @@ then 3. click on "Load Temporary Add-on..." 4. select the `dist/firefox` folder +## Testing the Extension + +### Development Mode with Live Reload + +For active development with automatic rebuilding: + +**Chrome:** +```bash +npm run watch:chrome +``` + +**Firefox:** +```bash +npm run watch:firefox +``` + +This will automatically rebuild the extension when you make changes to the source code. + +### Manual Testing Steps + +Once the extension is loaded in your browser: + +#### 1. Initial Setup +1. Click the Gooti extension icon in your browser toolbar +2. Create a new vault or import an existing one +3. Create or import a Nostr identity + +#### 2. Test Relay Management +1. Navigate to an identity's relay settings +2. Test adding relays with different formats: + - `relay.example.com` (should auto-add `wss://` prefix) + - `ws://relay.example.com` (should preserve `ws://` prefix) + - `wss://relay.example.com` (should preserve `wss://` prefix) + - URLs without trailing slash (should auto-add `/`) +3. Verify that the input field updates to show the complete URL after adding +4. Test read/write permissions for relays +5. Test removing relays + +#### 3. Test NIP-07 Integration +Visit a Nostr web application (like [Snort](https://snort.social) or [Iris](https://iris.to)) and test: + +1. **Public Key Access:** + - The app should be able to request your public key + - Gooti should prompt for permission + - Verify the correct public key is returned + +2. **Event Signing:** + - Try posting a note or performing actions that require signing + - Gooti should prompt to sign events + - Verify events are properly signed + +3. **Relay Information:** + - Apps should be able to access your relay list + - Verify the correct relays are returned with proper read/write flags + +4. **Encryption/Decryption (NIP-04 & NIP-44):** + - Test direct messaging features + - Verify encryption and decryption work properly + +#### 4. Test Identity Management +1. Create multiple identities +2. Switch between identities +3. Test that each identity has its own relay configuration +4. Test identity export/import functionality + +#### 5. Test Vault Security +1. Lock the vault and verify it requires password to unlock +2. Test vault backup and restore +3. Verify that sensitive data is properly encrypted + +### Automated Testing + +Run the test suite: +```bash +npm test +``` + +Run linting: +```bash +npm run lint +``` + +### Browser-Specific Testing + +#### Chrome-specific features: +- Test extension popup behavior +- Verify manifest v3 compatibility +- Test service worker functionality + +#### Firefox-specific features: +- Test extension sidebar (if applicable) +- Verify manifest v2 compatibility +- Test background script functionality + +### Performance Testing +1. Test with multiple identities (10+) +2. Test with many relays per identity (20+) +3. Monitor memory usage during extended use +4. Test extension startup time + +### Security Testing +1. Verify that private keys are never exposed to web pages +2. Test that permissions are properly requested and enforced +3. Verify that vault encryption is working correctly +4. Test that the extension works properly in incognito/private browsing mode + --- LICENSE: Public Domain \ No newline at end of file diff --git a/projects/chrome/src/app/components/edit-identity/relays/relays.component.html b/projects/chrome/src/app/components/edit-identity/relays/relays.component.html index 68b9893..0bd3c86 100644 --- a/projects/chrome/src/app/components/edit-identity/relays/relays.component.html +++ b/projects/chrome/src/app/components/edit-identity/relays/relays.component.html @@ -40,7 +40,7 @@ type="text" (focus)="addRelayInputHasFocus = true" (blur)="addRelayInputHasFocus = false" - [placeholder]="addRelayInputHasFocus ? 'server.com' : 'Add a relay'" + [placeholder]="addRelayInputHasFocus ? 'wss://server.com' : 'Add a relay'" class="form-control" [(ngModel)]="newRelay.url" (ngModelChange)="evaluateCanAdd()" diff --git a/projects/chrome/src/app/components/edit-identity/relays/relays.component.ts b/projects/chrome/src/app/components/edit-identity/relays/relays.component.ts index b43c3b9..d399f59 100644 --- a/projects/chrome/src/app/components/edit-identity/relays/relays.component.ts +++ b/projects/chrome/src/app/components/edit-identity/relays/relays.component.ts @@ -86,9 +86,23 @@ export class RelaysComponent extends NavComponent implements OnInit { } try { + let processedUrl = this.newRelay.url.trim(); + + // If no protocol prefix, assume wss:// + if (!processedUrl.startsWith('ws://') && !processedUrl.startsWith('wss://')) { + processedUrl = 'wss://' + processedUrl; + // Update the input field to show the added protocol + this.newRelay.url = processedUrl; + } + + // Add trailing slash if not present + if (!processedUrl.endsWith('/')) { + processedUrl += '/'; + } + await this.#storage.addRelay({ identityId: this.identity.id, - url: 'wss://' + this.newRelay.url.toLowerCase(), + url: processedUrl, read: this.newRelay.read, write: this.newRelay.write, }); diff --git a/projects/common/src/lib/pipes/visual-relay.pipe.ts b/projects/common/src/lib/pipes/visual-relay.pipe.ts index d92a1dd..636e8bb 100644 --- a/projects/common/src/lib/pipes/visual-relay.pipe.ts +++ b/projects/common/src/lib/pipes/visual-relay.pipe.ts @@ -5,6 +5,6 @@ import { Pipe, PipeTransform } from '@angular/core'; }) export class VisualRelayPipe implements PipeTransform { transform(value: string): string { - return value.toLowerCase().replaceAll('wss://', ''); + return value.toLowerCase().replace(/^wss?:\/\//, '').replace(/\/$/, ''); } } diff --git a/projects/firefox/src/app/components/edit-identity/relays/relays.component.html b/projects/firefox/src/app/components/edit-identity/relays/relays.component.html index 68b9893..0bd3c86 100644 --- a/projects/firefox/src/app/components/edit-identity/relays/relays.component.html +++ b/projects/firefox/src/app/components/edit-identity/relays/relays.component.html @@ -40,7 +40,7 @@ type="text" (focus)="addRelayInputHasFocus = true" (blur)="addRelayInputHasFocus = false" - [placeholder]="addRelayInputHasFocus ? 'server.com' : 'Add a relay'" + [placeholder]="addRelayInputHasFocus ? 'wss://server.com' : 'Add a relay'" class="form-control" [(ngModel)]="newRelay.url" (ngModelChange)="evaluateCanAdd()" diff --git a/projects/firefox/src/app/components/edit-identity/relays/relays.component.ts b/projects/firefox/src/app/components/edit-identity/relays/relays.component.ts index c4b1468..21203f2 100644 --- a/projects/firefox/src/app/components/edit-identity/relays/relays.component.ts +++ b/projects/firefox/src/app/components/edit-identity/relays/relays.component.ts @@ -86,9 +86,23 @@ export class RelaysComponent extends NavComponent implements OnInit { } try { + let processedUrl = this.newRelay.url.trim(); + + // If no protocol prefix, assume wss:// + if (!processedUrl.startsWith('ws://') && !processedUrl.startsWith('wss://')) { + processedUrl = 'wss://' + processedUrl; + // Update the input field to show the added protocol + this.newRelay.url = processedUrl; + } + + // Add trailing slash if not present + if (!processedUrl.endsWith('/')) { + processedUrl += '/'; + } + await this.#storage.addRelay({ identityId: this.identity.id, - url: 'wss://' + this.newRelay.url.toLowerCase(), + url: processedUrl, read: this.newRelay.read, write: this.newRelay.write, });