Files
orbithub/tests/test_mremoteng_importer_fixtures.h
T
ksmithandClaude Sonnet 5 dbcc20d155 Add File -> Import from mRemoteNG...
Parses mRemoteNG's confCons.xml export format directly -- schema verified
against mRemoteNG's own XmlConnectionsDeserializer.cs source and a real
exported sample, not guessed at. Maps nested <Node Type="Container">
folders and <Node Type="Connection"> entries onto OrbitHub profiles:
RDP stays RDP, SSH1/SSH2 collapse to OrbitHub's single SSH protocol,
anything else (VNC, Telnet, HTTP, PowerShell, ...) is skipped and listed
in the import summary rather than silently dropped.

Passwords are never read, not even for the common case where they're
technically readable without a master password (mRemoteNG only encrypts
the Password attribute itself, everything else -- Hostname, Username,
Domain, Protocol -- is plaintext). A FullFileEncryption="true" export
encrypts the whole node tree instead and genuinely can't be read without
the user's master password; that case is detected and refused with a
clear message rather than failing confusingly.

The parser (src/mremoteng_importer.h/.cpp) is a pure function decoupled
from any file/UI I/O, matching this session's established pattern of
keeping business logic separately testable from the Qt Widgets shell that
calls it (ProfilesWindow::importFromMRemoteNG() is the thin wrapper:
QFileDialog, call the parser, write results via ProfileRepository, show a
summary). 11 test cases against realistic sample XML.

Hit a real moc gotcha along the way: a literal "//" inside a raw string
literal (the xmlns URL) makes moc's lexer think a line comment started
there, silently desyncing its parse so it never finds the QObject-derived
test class at all (no error, just a missing vtable at link time). Fixed
by moving the XML fixtures into a plain non-QObject header moc never
scans, split across two adjacent literals as a second safeguard.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-15 16:08:02 -06:00

48 lines
2.4 KiB
C

#ifndef ORBITHUB_TEST_MREMOTENG_IMPORTER_FIXTURES_H
#define ORBITHUB_TEST_MREMOTENG_IMPORTER_FIXTURES_H
// Kept out of the moc-processed test .cpp: a literal "//" inside a raw
// string literal (as in the xmlns URL below) confuses moc's lexer into
// thinking a line comment started there, which silently desyncs the rest
// of its parse and drops the QObject-derived test class entirely (no
// error, just "No relevant classes found" and a missing vtable at link
// time). Plain, non-QObject headers are never moc-scanned, so this is
// immune to that.
// Modeled on a real mRemoteNG confCons.xml export (attribute names and
// root-element shape verified against mRemoteNG's own
// XmlConnectionsDeserializer.cs and a real exported sample), covering:
// nested folders, an RDP connection, an SSH2 connection (protocol must
// map to "SSH"), and a VNC connection (unsupported -- must be skipped,
// not dropped silently).
inline const char* mRemoteNGSampleXml()
{
return R"(<?xml version="1.0" encoding="utf-8"?>
<mrng:Connections xmlns:mrng="http:)" R"(//mremoteng.org" Name="Connections" Export="false" EncryptionEngine="AES" BlockCipherMode="GCM" KdfIterations="1000" FullFileEncryption="false" Protected="" ConfVersion="2.6">
<Node Name="Work" Type="Container" Descr="" Expanded="true">
<Node Name="DC" Type="Connection" Descr="" Username="Administrator" Domain="CORP" Password="aEWNFV5uGcjUHF0uS17QTdT9kVqtKCPeoC0Nw5dmaPFjNQ2kt/zO5xDqE4HdVmHAowVRdC7emf7lWWA10dQKiw==" Hostname="10.0.0.5" Protocol="RDP" Port="3389" />
<Node Name="Servers" Type="Container" Descr="" Expanded="true">
<Node Name="build-box" Type="Connection" Descr="" Username="deploy" Domain="" Password="yhgmiu5bbuamU3qMUKc/uYDdmbMrJZ" Hostname="build.internal" Protocol="SSH2" Port="22" />
</Node>
</Node>
<Node Name="oldkiosk" Type="Connection" Descr="" Username="" Domain="" Password="" Hostname="kiosk.internal" Protocol="VNC" Port="5900" />
</mrng:Connections>
)";
}
inline const char* mRemoteNGFullFileEncryptedXml()
{
return R"(<?xml version="1.0" encoding="utf-8"?>
<mrng:Connections xmlns:mrng="http:)" R"(//mremoteng.org" Name="Connections" Export="false" EncryptionEngine="AES" BlockCipherMode="GCM" KdfIterations="1000" FullFileEncryption="true" Protected="somehash" ConfVersion="2.6">SomeOpaqueBase64Blob==</mrng:Connections>
)";
}
inline const char* mRemoteNGWrongRootXml()
{
return R"(<?xml version="1.0" encoding="utf-8"?>
<SomeOtherFormat/>
)";
}
#endif