Files
Bubberstation/code/modules/unit_tests/load_map_security.dm
SkyratBot 551fa984bb [MIRROR] Map load unit testing and directory whitelisting - Mojave Sun is a really cool downstream, like and subscribe for longer PR names. oranges was here and made this github PR name much longer, thereby proving once and for all that upstreams do add value to the downstream not just endless amounts of refactoring because we can't write any api's in a modular fashion the first time around so have to update them later to be modular. Anyway do you think a taco counts as a sandwich? [MDB IGNORE] (#9290)
* Map load unit testing and directory whitelisting - Mojave Sun is a really cool downstream, like and subscribe for longer PR names. oranges was here and made this github PR name much longer, thereby proving once and for all that upstreams do add value to the downstream not just endless amounts of refactoring because we can't write any api's in a modular fashion the first time around so have to update them later to be modular. Anyway do you think a taco counts as a sandwich? (#62620)

About The Pull Request

This is a fix for map not load anymore because of security changes
Why It's Good For The Game

Maps are good as they encourage gameplay and differentiate ss13 from a classic MUD game
Changelog

cl
add: unit test for map load
add: directory param to map load + whitelist for data and _maps
add: advertising for mojave sun in tg commit logs
/cl

* Map load unit testing and directory whitelisting - Mojave Sun is a really cool downstream, like and subscribe for longer PR names. oranges was here and made this github PR name much longer, thereby proving once and for all that upstreams do add value to the downstream not just endless amounts of refactoring because we can't write any api's in a modular fashion the first time around so have to update them later to be modular. Anyway do you think a taco counts as a sandwich?

Co-authored-by: AndrewL97 <andrewjlove97@gmail.com>
2021-11-07 08:09:43 -05:00

43 lines
1.7 KiB
Plaintext

// replace runtimestation with another valid _maps .json if not present
#define VALID_TEST_MAP "runtimestation"
/// Tests to ensure we can load a map from a whitelisted directory (_maps), but not a non-whitelisted directory (i.e "fartyShitPants")
/datum/unit_test/load_map_security
/datum/unit_test/load_map_security/Run()
// Copy our valid map into a bad directory
// We can technically load from /unitTestTempDir by passing it in our map name
// But it should fail when passed as a directory
fcopy("_maps/[VALID_TEST_MAP].json", "data/load_map_security_temp/[VALID_TEST_MAP].json")
//Attempt to load our configs
// test load from _maps - this should pass
var/datum/map_config/maps_config = load_map_config(VALID_TEST_MAP, MAP_DIRECTORY_MAPS)
// test load from data - this should pass
// this also confirms that our fcopy worked for our bad_config test
var/datum/map_config/data_config = load_map_config("load_map_security_temp/[VALID_TEST_MAP]", MAP_DIRECTORY_DATA)
// data/load_map_security_temp/ is not in our whitelist, this should fail
var/datum/map_config/bad_config = load_map_config(VALID_TEST_MAP,"data/load_map_security_temp")
// Check we can load from _maps
TEST_ASSERT(!maps_config.defaulted, "Failed to load: _maps/[VALID_TEST_MAP]")
// Check we can load from data and ensure that our fcopy setup worked
TEST_ASSERT(!data_config.defaulted, "Failed to load: data/load_map_security_temp/[VALID_TEST_MAP]")
// Check we can't load from "bad directory"
TEST_ASSERT(bad_config.defaulted, "Loaded from non-whitelisted directory: data/load_map_security_temp/[VALID_TEST_MAP]")
/datum/unit_test/load_map_security/Destroy()
// Clean up our temp directory
fdel("data/load_map_security_temp/")
return ..()
#undef VALID_TEST_MAP