fix(#1103): lock a hashtag channel's PSK in Edit Channel, derive on rename
User report (Jeremy AA4KY, iOS; one codebase so the fix is platform-wide): the Edit Channel dialog was type-blind, offering a free-text PSK field and a random-PSK die for every channel. A hashtag channel's key IS its name, so hand-editing it silently diverges the channel from everyone else on that hashtag. - hashtag: key read-only and copyable (copy icon replaces the die), derived live from the name while renaming, exactly as adding that hashtag would. Save refuses a name that stops being a hashtag or carries a double '#' (a '##name' hashes differently), inline error. - community hashtag: name and key both read-only (community-secret derived), key copyable. - private/public/communityPublic: unchanged. - Save also refuses, with a persistent error, when the slot's live occupant no longer matches the channel the dialog opened on, so a background sync replacing the slot mid-edit (the 1060 class) cannot be overwritten by a stale dialog (review finding). Policy helpers are unit-tested; with both guards behaviorally disabled 2 tests fail. Suite 1903 passed / 1 skipped. English strings only; untranslated.json regenerated. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>pull/1104/head
parent
dd09084a9b
commit
4352ed8ac5
@ -0,0 +1,68 @@
|
||||
// #1103: the Edit Channel dialog must never let a hashtag channel's key be
|
||||
// hand-edited, because the key derives from the name (a user report: editing
|
||||
// it silently diverges the channel from everyone else on that hashtag).
|
||||
// These tests pin the dialog's edit policy and the rename re-derivation.
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:meshcore_open/models/channel.dart';
|
||||
import 'package:meshcore_open/screens/channels_screen.dart';
|
||||
|
||||
void main() {
|
||||
group('channelPskEditable', () {
|
||||
test('locked for name-derived and community-derived keys', () {
|
||||
expect(channelPskEditable(ChannelType.hashtag), isFalse);
|
||||
expect(channelPskEditable(ChannelType.communityHashtag), isFalse);
|
||||
});
|
||||
|
||||
test('editable for the rest', () {
|
||||
expect(channelPskEditable(ChannelType.private), isTrue);
|
||||
expect(channelPskEditable(ChannelType.public), isTrue);
|
||||
expect(channelPskEditable(ChannelType.communityPublic), isTrue);
|
||||
});
|
||||
});
|
||||
|
||||
group('channelNameEditable', () {
|
||||
test('only a community hashtag locks its name', () {
|
||||
expect(channelNameEditable(ChannelType.communityHashtag), isFalse);
|
||||
expect(channelNameEditable(ChannelType.hashtag), isTrue);
|
||||
expect(channelNameEditable(ChannelType.private), isTrue);
|
||||
expect(channelNameEditable(ChannelType.public), isTrue);
|
||||
expect(channelNameEditable(ChannelType.communityPublic), isTrue);
|
||||
});
|
||||
});
|
||||
|
||||
group('editedNameKeepsType', () {
|
||||
test('a hashtag channel must keep a usable # name', () {
|
||||
expect(editedNameKeepsType(ChannelType.hashtag, '#other'), isTrue);
|
||||
expect(editedNameKeepsType(ChannelType.hashtag, 'other'), isFalse);
|
||||
expect(editedNameKeepsType(ChannelType.hashtag, '#'), isFalse);
|
||||
expect(editedNameKeepsType(ChannelType.hashtag, ''), isFalse);
|
||||
// '##name' hashes differently from the '#name' everyone else derives,
|
||||
// so a double hash is refused rather than silently isolating the user.
|
||||
expect(editedNameKeepsType(ChannelType.hashtag, '##general'), isFalse);
|
||||
});
|
||||
|
||||
test('non-hashtag channels are unconstrained', () {
|
||||
expect(editedNameKeepsType(ChannelType.private, 'anything'), isTrue);
|
||||
expect(editedNameKeepsType(ChannelType.public, ''), isTrue);
|
||||
});
|
||||
});
|
||||
|
||||
group('rename re-derivation', () {
|
||||
test('a renamed hashtag derives exactly what adding it would', () {
|
||||
// The add flow strips the '#' before deriving; the edit flow passes the
|
||||
// '#'-prefixed name. Both must land on the same key.
|
||||
expect(
|
||||
Channel.derivePskFromHashtag('#wardriving'),
|
||||
Channel.derivePskFromHashtag('wardriving'),
|
||||
);
|
||||
});
|
||||
|
||||
test('different hashtags derive different keys', () {
|
||||
expect(
|
||||
Channel.derivePskFromHashtag('#test'),
|
||||
isNot(Channel.derivePskFromHashtag('#wardriving')),
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
Loading…
Reference in new issue