Assert.That(ParseBaseUrl(value).AbsoluteUri,Is.EqualTo(expected),"Without the slash, resolving the search page against the base URL would replace its last segment, and with more than one, no page of the wiki would count as within it.");
Assert.That(ConfluenceSearchTool.TryParseBaseUrl(value,outvarbaseUrl),Is.False,"Plain HTTP would expose the sign-in, credentials in the address would travel with every request, and a query or fragment has no place in the root of a wiki.");
Assert.That(searchUrl.GetLeftPart(UriPartial.Path),Is.EqualTo("https://wiki.example.org/confluence/dosearchsite.action"),"The search page lies below the context path of the wiki, even when the configured address lacks the final slash.");
Assert.That(parameters["cql"],Is.EqualTo("siteSearch ~ \"release plan\""),"The search box of the wiki sends the same field, so the tool finds the pages the user would find there.");
Assert.That(parameters["queryString"],Is.EqualTo("release plan"),"Confluence shows these words in its search field, so the page reads like a search the user made.");
// The words land inside a quoted CQL string. Were a quote to end it, or a trailing backslash
// to turn the closing quote into a literal one, a model could append conditions of its own,
// such as one which widens the search to spaces the user never asked for:
//
Assert.That(Cql(ConfluenceSearchTool.BuildSearchUrl(WIKI,query,null)),Is.EqualTo(expectedCql),"Backslashes are escaped first and quotes second, so neither can end the string.");
Assert.That(Cql(ConfluenceSearchTool.BuildSearchUrl(WIKI,"release plan",@"DEV"" or space = ""HR")),Is.EqualTo(@"siteSearch ~ ""release plan"" and space=""DEV\"" or space = \""HR"""),"The space key comes from the model as well, so it gets the same escaping as the words.");
Assert.That(Cql(ConfluenceSearchTool.BuildSearchUrl(WIKI,"release plan",spaceKey)),Is.EqualTo("siteSearch ~ \"release plan\""),"An empty space key would otherwise ask for a space which does not exist and find nothing.");
Assert.That(ConfluenceSearchTool.IsWithinWiki(WIKI,newUri(url)),Is.True,"The case of the host, the default port written out, and a trailing dot all name the same wiki.");
Assert.That(ConfluenceSearchTool.IsWithinWiki(WIKI,newUri(url)),Is.False,"A neighbouring path, a path which climbs out, another port, plain HTTP, or another host is not the configured wiki, however similar it looks.");
Assert.That(ConfluenceSearchTool.IsLoginPage(newUri(url)),Is.True,"Confluence answers a search without a valid session with its login page, or with another page that carries the search as the destination to return to.");
Assert.That(ConfluenceSearchTool.IsLoginPage(searchUrl),Is.False,"Somebody looking up the login page in the wiki gets search results, not a message saying that the sign-in failed.");