-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix #2804 Disable OSDD processing when SSO is active to enhance usabi…
…lity
- Loading branch information
Showing
7 changed files
with
224 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
169 changes: 169 additions & 0 deletions
169
src/test/java/org/codelibs/fess/helper/OsddHelperTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
/* | ||
* Copyright 2012-2023 CodeLibs Project and the Others. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, | ||
* either express or implied. See the License for the specific language | ||
* governing permissions and limitations under the License. | ||
*/ | ||
package org.codelibs.fess.helper; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.OutputStream; | ||
|
||
import org.codelibs.core.io.InputStreamUtil; | ||
import org.codelibs.fess.Constants; | ||
import org.codelibs.fess.mylasta.direction.FessConfig; | ||
import org.codelibs.fess.unit.UnitFessTestCase; | ||
import org.codelibs.fess.util.ComponentUtil; | ||
import org.lastaflute.web.response.StreamResponse; | ||
import org.lastaflute.web.servlet.request.stream.WrittenStreamOut; | ||
|
||
public class OsddHelperTest extends UnitFessTestCase { | ||
|
||
public void test_init_nofile() { | ||
ComponentUtil.setFessConfig(new FessConfig.SimpleImpl() { | ||
@Override | ||
public String getOsddLinkEnabled() { | ||
return "auto"; | ||
} | ||
|
||
@Override | ||
public String getSsoType() { | ||
return "none"; | ||
} | ||
}); | ||
final OsddHelper osddHelper = new OsddHelper(); | ||
osddHelper.setContentType("application/opensearchdescription+xml"); | ||
osddHelper.init(); | ||
assertFalse(osddHelper.hasOpenSearchFile()); | ||
|
||
try { | ||
osddHelper.asStream(); | ||
fail(); | ||
} catch (final Exception e) { | ||
assertEquals("Unsupported Open Search Description Document response.", e.getMessage()); | ||
} | ||
} | ||
|
||
public void test_init_osddpath() throws IOException { | ||
ComponentUtil.setFessConfig(new FessConfig.SimpleImpl() { | ||
@Override | ||
public String getOsddLinkEnabled() { | ||
return "auto"; | ||
} | ||
|
||
@Override | ||
public String getSsoType() { | ||
return "none"; | ||
} | ||
}); | ||
final OsddHelper osddHelper = new OsddHelper(); | ||
osddHelper.setOsddPath("osdd/osdd.xml"); | ||
osddHelper.setEncoding(Constants.UTF_8); | ||
osddHelper.init(); | ||
assertTrue(osddHelper.hasOpenSearchFile()); | ||
|
||
final StreamResponse streamResponse = osddHelper.asStream(); | ||
assertEquals("text/xml; charset=UTF-8", streamResponse.getContentType()); | ||
streamResponse.getStreamCall().callback(new WrittenStreamOut() { | ||
|
||
@Override | ||
public void write(final InputStream ins) throws IOException { | ||
assertEquals(""" | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/"> | ||
<ShortName>Fess</ShortName> | ||
<Description>Full Text Search for Your Documents.</Description> | ||
<Tags>Full Text Search</Tags> | ||
<Contact>[email protected]</Contact> | ||
<SearchForm>http://localhost:8080/fess/</SearchForm> | ||
<Url type="text/html" template="http://localhost:8080/fess/search?q={searchTerms}"/> | ||
<InputEncoding>UTF-8</InputEncoding> | ||
<OutputEncoding>UTF-8</OutputEncoding> | ||
</OpenSearchDescription> | ||
""", new String(InputStreamUtil.getBytes(ins))); | ||
} | ||
|
||
@Override | ||
public OutputStream stream() { | ||
return null; | ||
} | ||
}); | ||
} | ||
|
||
public void test_init_osddpath_null() { | ||
ComponentUtil.setFessConfig(new FessConfig.SimpleImpl() { | ||
@Override | ||
public String getOsddLinkEnabled() { | ||
return "auto"; | ||
} | ||
|
||
@Override | ||
public String getSsoType() { | ||
return "none"; | ||
} | ||
}); | ||
final OsddHelper osddHelper = new OsddHelper(); | ||
osddHelper.setOsddPath("osdd/none.xml"); | ||
osddHelper.init(); | ||
assertFalse(osddHelper.hasOpenSearchFile()); | ||
} | ||
|
||
public void test_init_disabled() { | ||
ComponentUtil.setFessConfig(new FessConfig.SimpleImpl() { | ||
@Override | ||
public String getOsddLinkEnabled() { | ||
return "false"; | ||
} | ||
}); | ||
final OsddHelper osddHelper = new OsddHelper(); | ||
osddHelper.setOsddPath("osdd/osdd.xml"); | ||
osddHelper.init(); | ||
assertFalse(osddHelper.hasOpenSearchFile()); | ||
} | ||
|
||
public void test_init_saml() { | ||
ComponentUtil.setFessConfig(new FessConfig.SimpleImpl() { | ||
@Override | ||
public String getOsddLinkEnabled() { | ||
return "auto"; | ||
} | ||
|
||
@Override | ||
public String getSsoType() { | ||
return "saml"; | ||
} | ||
}); | ||
final OsddHelper osddHelper = new OsddHelper(); | ||
osddHelper.setOsddPath("osdd/osdd.xml"); | ||
osddHelper.init(); | ||
assertFalse(osddHelper.hasOpenSearchFile()); | ||
} | ||
|
||
public void test_init_force() throws IOException { | ||
ComponentUtil.setFessConfig(new FessConfig.SimpleImpl() { | ||
@Override | ||
public String getOsddLinkEnabled() { | ||
return "true"; | ||
} | ||
|
||
@Override | ||
public String getSsoType() { | ||
return "saml"; | ||
} | ||
}); | ||
final OsddHelper osddHelper = new OsddHelper(); | ||
osddHelper.setOsddPath("osdd/osdd.xml"); | ||
osddHelper.init(); | ||
assertTrue(osddHelper.hasOpenSearchFile()); | ||
} | ||
} |