Repository: enowars/enochecker

Issue:
Do not return OK when previous putflag/putnoise wasn't successful
See https://github.com/enowars/enochecker/blob/master/src/enochecker/enochecker.py#L416


Discussion:

Patch:
diff --git a/src/enochecker/enochecker.py b/src/enochecker/enochecker.py
index 831cb5b..6ddc1ef 100644
--- a/src/enochecker/enochecker.py
+++ b/src/enochecker/enochecker.py
@@ -395,9 +395,6 @@ class BaseChecker(metaclass=_CheckerMeta):
             1,
         )
 
-    # def __format_internal_db_entry(name):
-    #     return f"__Checker-Internals:{name}__"
-
     # ---- Basic checker functionality ---- #
 
     def _run_method(self, method: Optional[str] = None) -> Optional[Result]:
@@ -413,22 +410,6 @@ class BaseChecker(metaclass=_CheckerMeta):
                 "Method {} not supported! Supported: {}".format(method, CHECKER_METHODS)
             )
 
-        # handle the cases where the original putflag/putnoise wasn't successful
-        if method == "getflag":
-            key = f"__Checker-internals-RESULT:putflag,{self.flag_round},{self.flag_idx}__"
-            if key not in self.team_db or self.team_db[key] != "OK":
-                self.info(
-                    f"original putflag did not return successfully -- ignoring getflag for flag_round:{self.flag_round}, index: {self.flag_idx}"
-                )
-                return Result.OK
-        elif method == "getnoise":
-            key = f"__Checker-internals-RESULT:putnoise,{self.flag_round},{self.flag_idx}__"
-            if key not in self.team_db or self.team_db[key] != "OK":
-                self.info(
-                    f"original putnoise did not return successfully -- ignoring getnoise for flag_round:{self.flag_round}, index: {self.flag_idx}"
-                )
-                return Result.OK
-
         return getattr(self, snake_caseify(method))()
 
     def run(self, method: Optional[str] = None) -> CheckerResult:
@@ -456,16 +437,10 @@ class BaseChecker(metaclass=_CheckerMeta):
                 # Better wrap this, in case somebody returns raw ints (?)
                 ret = Result(ret)
                 self.info("Checker [{}] resulted in {}".format(self.method, ret.name))
-                self.team_db[
-                    f"__Checker-internals-RESULT:{str(method)},{self.flag_round},{self.flag_idx}__"
-                ] = ret.name
                 return CheckerResult(ret)
 
             # Returned Normally
             self.info("Checker [{}] executed successfully!".format(self.method))
-            self.team_db[
-                f"__Checker-internals-RESULT:{str(method)},{self.flag_round},{self.flag_idx}__"
-            ] = "OK"
             return CheckerResult(Result.OK)
 
         except EnoException as eno:


Test patch:
diff --git a/tests/test_run_method.py b/tests/test_run_method.py
index d059e30..e672ecd 100644
--- a/tests/test_run_method.py
+++ b/tests/test_run_method.py
@@ -87,18 +87,6 @@ def test_run_return_status(method, result, checker_cls):
     def meth(self):
         return result
 
-    def ok(self):
-        return Result.OK
-
-    if method == "getflag":
-        setattr(checker_cls, "putflag", ok)
-        c = checker_cls("putflag")
-        c.run()
-    elif method == "getnoise":
-        setattr(checker_cls, "putnoise", ok)
-        c = checker_cls("putnoise")
-        c.run()
-
     setattr(checker_cls, method, meth)
     c = checker_cls(method)
     res = c.run()
@@ -106,35 +94,11 @@ def test_run_return_status(method, result, checker_cls):
     assert res.result == result
 
 
-@pytest.mark.parametrize("method", ["getflag", "getnoise"])
-def test_run_get_original_run_failed(method, checker_cls):
-    def meth(self):
-        assert False  # this function should never be called
-
-    setattr(checker_cls, method, meth)
-    c = checker_cls(method)
-    res = c.run()
-    assert isinstance(res, CheckerResult)
-    assert res.result == Result.OK
-
-
 @pytest.mark.parametrize("method", CHECKER_METHODS)
 def test_raise_broken_service_exception(method, checker_cls):
     def meth(self):
         raise BrokenServiceException("msg123")
 
-    def ok(self):
-        return Result.OK
-
-    if method == "getflag":
-        setattr(checker_cls, "putflag", ok)
-        c = checker_cls("putflag")
-        c.run()
-    elif method == "getnoise":
-        setattr(checker_cls, "putnoise", ok)
-        c = checker_cls("putnoise")
-        c.run()
-
     setattr(checker_cls, method, meth)
     c = checker_cls(method)
     res = c.run()
@@ -148,18 +112,6 @@ def test_raise_offline_exception(method, checker_cls):
     def meth(self):
         raise OfflineException("msg123")
 
-    def ok(self):
-        return Result.OK
-
-    if method == "getflag":
-        setattr(checker_cls, "putflag", ok)
-        c = checker_cls("putflag")
-        c.run()
-    elif method == "getnoise":
-        setattr(checker_cls, "putnoise", ok)
-        c = checker_cls("putnoise")
-        c.run()
-
     setattr(checker_cls, method, meth)
     c = checker_cls(method)
     res = c.run()
@@ -173,18 +125,6 @@ def test_raise_unhandled_exception(method, checker_cls):
     def meth(self):
         raise Exception("msg123")
 
-    def ok(self):
-        return Result.OK
-
-    if method == "getflag":
-        setattr(checker_cls, "putflag", ok)
-        c = checker_cls("putflag")
-        c.run()
-    elif method == "getnoise":
-        setattr(checker_cls, "putnoise", ok)
-        c = checker_cls("putnoise")
-        c.run()
-
     setattr(checker_cls, method, meth)
     c = checker_cls(method)
     res = c.run()
@@ -200,18 +140,6 @@ def test_invalid_return(method, checker_cls):
     def meth(self):
         return "lolthisisinvalid"
 
-    def ok(self):
-        return Result.OK
-
-    if method == "getflag":
-        setattr(checker_cls, "putflag", ok)
-        c = checker_cls("putflag")
-        c.run()
-    elif method == "getnoise":
-        setattr(checker_cls, "putnoise", ok)
-        c = checker_cls("putnoise")
-        c.run()
-
     setattr(checker_cls, method, meth)
     c = checker_cls(method)
     res = c.run()
@@ -236,18 +164,6 @@ def test_requests_mumble(method, exc, checker_cls):
     def meth(self):
         raise exc()
 
-    def ok(self):
-        return Result.OK
-
-    if method == "getflag":
-        setattr(checker_cls, "putflag", ok)
-        c = checker_cls("putflag")
-        c.run()
-    elif method == "getnoise":
-        setattr(checker_cls, "putnoise", ok)
-        c = checker_cls("putnoise")
-        c.run()
-
     setattr(checker_cls, method, meth)
     c = checker_cls(method)
     res = c.run()
@@ -275,18 +191,6 @@ def test_offline_exceptions(method, exc, checker_cls):
     def meth(self):
         raise exc()
 
-    def ok(self):
-        return Result.OK
-
-    if method == "getflag":
-        setattr(checker_cls, "putflag", ok)
-        c = checker_cls("putflag")
-        c.run()
-    elif method == "getnoise":
-        setattr(checker_cls, "putnoise", ok)
-        c = checker_cls("putnoise")
-        c.run()
-
     setattr(checker_cls, method, meth)
     c = checker_cls(method)
     res = c.run()