Skip to content

test(nostr): unit test Blossom.buildServerListTags#614

Open
NicolaLS wants to merge 4 commits into
barrydeen:mainfrom
NicolaLS:test/unit-tests-buildServerListTags
Open

test(nostr): unit test Blossom.buildServerListTags#614
NicolaLS wants to merge 4 commits into
barrydeen:mainfrom
NicolaLS:test/unit-tests-buildServerListTags

Conversation

@NicolaLS

@NicolaLS NicolaLS commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

noticed a quality issue here:

fun addServer() {
val raw = _newServerUrl.value.trim().trimEnd('/')
if (raw.isBlank()) return
if (raw.startsWith("http://")) {
_error.value = "Only HTTPS servers are supported"
return
}
val url = if (raw.startsWith("https://")) raw else "https://$raw"
val current = servers.value.toMutableList()
if (current.contains(url)) {
_error.value = "Server already added"
return
}
current.add(url)
blossomRepo.saveBlossomServers(current)
_newServerUrl.value = ""
_error.value = null
}

this function allows lots of bad stuff eg.

  • example com -> https://example com
  • HTTPS://example.com -> https://HTTPS://example.com
  • ftp://example.com -> https://ftp://example.com

Also allows fragments (#) and query parameters (?) in url that can be an issue when appending /media in the repository. It should be defined whether we allow something like https://example.com?query=a#fragment and then append /media like this https://example.com/media?query=a#fragment or just don't allow it.

Correct validation logic should be used for user input as well as when parsing kind 10063 events.

@NicolaLS

NicolaLS commented Jul 6, 2026

Copy link
Copy Markdown
Contributor Author

I guess pointing out the validation problem in this PR is not optimal but I noticed it when implementing these unit tests as I decided not to add url validation to the builder method because that would be unnecessary overhead, its quite far away from the UI/wire and should not own validation which is why I checked whether the components that do own it do it properly.

NicolaLS added 2 commits July 6, 2026 08:12
Covers the builder's current contract: it rejects an empty server
listand maps already-validated server URLs into BUD-03 server tags.
Invalid URL strings are **intentionally** not tested here because URL
validation is owned by the repository/viewmodel boundary before values
reach this helper.
@NicolaLS NicolaLS force-pushed the test/unit-tests-buildServerListTags branch from 7ddc4d5 to f9cd22b Compare July 6, 2026 14:12
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.

1 participant