Search in sources :

Example 1 with Page

use of org.opennms.netmgt.model.OnmsFilterFavorite.Page in project opennms by OpenNMS.

the class FilterFavoriteServiceIT method setUp.

@Before
public void setUp() {
    populator.addExtension(new DatabasePopulator.Extension<FilterFavoriteDao>() {

        @Override
        public DaoSupport<FilterFavoriteDao> getDaoSupport() {
            return new DaoSupport<FilterFavoriteDao>(FilterFavoriteDao.class, service.getFilterFavoriteDao());
        }

        @Override
        public void onPopulate(DatabasePopulator populator, FilterFavoriteDao dao) {
            dao.save(createFavorite("mvr", "First Favorite 1", "filter=severity%3D6&amp;filter=node%3D2", OnmsFilterFavorite.Page.EVENT));
            dao.save(createFavorite("mvr", "First Favorite 2", "filter=severity%3D6&amp;filter=node%3D2", OnmsFilterFavorite.Page.EVENT));
            dao.save(createFavorite("mvr", "First Favorite 3", "filter=severity%3D6&amp;filter=node%3D2", OnmsFilterFavorite.Page.EVENT));
            dao.save(createFavorite("mvr", "First Favorite 1", "filter=severity%3D6&amp;filter=node%3D2", OnmsFilterFavorite.Page.ALARM));
            dao.save(createFavorite("mvr", "First Favorite 2", "filter=severity%3D6&amp;filter=node%3D2", OnmsFilterFavorite.Page.ALARM));
            dao.save(createFavorite("mvr", "First Favorite 3", "filter=severity%3D6&amp;filter=node%3D2", OnmsFilterFavorite.Page.ALARM));
        }

        @Override
        public void onShutdown(DatabasePopulator populator, FilterFavoriteDao dao) {
            for (OnmsFilterFavorite eachFavorite : dao.findAll()) {
                dao.delete(eachFavorite);
            }
        }

        private OnmsFilterFavorite createFavorite(String user, String filterName, String filterCriteria, Page page) {
            OnmsFilterFavorite favorite = new OnmsFilterFavorite();
            favorite.setName(filterName);
            favorite.setFilter(filterCriteria);
            favorite.setPage(page);
            favorite.setUsername(user);
            return favorite;
        }
    });
    populator.populateDatabase();
}
Also used : DaoSupport(org.opennms.netmgt.dao.DatabasePopulator.DaoSupport) OnmsFilterFavorite(org.opennms.netmgt.model.OnmsFilterFavorite) Page(org.opennms.netmgt.model.OnmsFilterFavorite.Page) FilterFavoriteDao(org.opennms.netmgt.dao.api.FilterFavoriteDao) DatabasePopulator(org.opennms.netmgt.dao.DatabasePopulator) Before(org.junit.Before)

Example 2 with Page

use of org.opennms.netmgt.model.OnmsFilterFavorite.Page in project opennms by OpenNMS.

the class FilterFavoriteServiceIT method verifyXSSPreventionOnRead.

// Due to NMS-9670 there may already be malicious data in the table, verify that we convert that correctly as well
@Test
public void verifyXSSPreventionOnRead() throws FilterFavoriteService.FilterFavoriteException {
    for (Page page : Page.values()) {
        final OnmsFilterFavorite filterToCreate = createFavoriteObject("ulf", "XSS Read Test " + page.name(), "filter=severity%3D6<script>alert(123);</script>", page);
        int filterId = service.getFilterFavoriteDao().save(filterToCreate);
        final OnmsFilterFavorite filterRead = service.getFavorite(filterId, "ulf");
        Assert.assertEquals("filter=severity=6&lt;script&gt;alert(123);&lt;/script&gt;", filterRead.getFilter());
    }
}
Also used : Page(org.opennms.netmgt.model.OnmsFilterFavorite.Page) OnmsFilterFavorite(org.opennms.netmgt.model.OnmsFilterFavorite) Test(org.junit.Test)

Example 3 with Page

use of org.opennms.netmgt.model.OnmsFilterFavorite.Page in project opennms by OpenNMS.

the class FilterFavoriteServiceIT method verifyXSSPreventionOnCreate.

@Test
public void verifyXSSPreventionOnCreate() throws FilterFavoriteService.FilterFavoriteException {
    final String maliciousName = "test<script>alert(123);</script>";
    final String maliciousFilter = "filter=severity=6<script>alert(123);</script>";
    for (Page page : Page.values()) {
        // try to create malicious favorites
        OnmsFilterFavorite favorite = service.createFavorite("ulf", maliciousName, maliciousFilter, page);
        // verify that filter name and criteria are not vulnerable to xss
        Assert.assertEquals(WebSecurityUtils.sanitizeString(maliciousName), favorite.getName());
        Assert.assertEquals(WebSecurityUtils.sanitizeString(maliciousFilter), favorite.getFilter());
    }
}
Also used : Page(org.opennms.netmgt.model.OnmsFilterFavorite.Page) OnmsFilterFavorite(org.opennms.netmgt.model.OnmsFilterFavorite) Test(org.junit.Test)

Aggregations

OnmsFilterFavorite (org.opennms.netmgt.model.OnmsFilterFavorite)3 Page (org.opennms.netmgt.model.OnmsFilterFavorite.Page)3 Test (org.junit.Test)2 Before (org.junit.Before)1 DatabasePopulator (org.opennms.netmgt.dao.DatabasePopulator)1 DaoSupport (org.opennms.netmgt.dao.DatabasePopulator.DaoSupport)1 FilterFavoriteDao (org.opennms.netmgt.dao.api.FilterFavoriteDao)1