Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A list of unit tests for authz.RPCCapability and authz.RPCCapabilities data class #206

Open
32 tasks
kefeimo opened this issue Aug 26, 2024 · 0 comments
Open
32 tasks

Comments

@kefeimo
Copy link

kefeimo commented Aug 26, 2024

Is your feature request related to a problem? Please describe.
A list of unit tests for authz.RPCCapability and authz.RPCCapabilities data class.
Note:

pin @craig8, @schandrika , @shwethanidd for discussion.

list of tests for authz.RPCCapability

  • data class definition

    • confirm param_restrictions = field(type=dict, default=None). Should type be Dict[str, List[str]], consider cases like authz.RPCCapability("id.rpc1", {"k1": ["v1", "v1a"], "k2":{}})
      [] negative:
      • Note: TODO: currently allow authz.RPCCapability("idrpc2"), but should we? If not, should we use regext to constrain the "key" as in . pattern?
  • init (empty init)
    [] Note: this is a negative test (assert Exception)

    • authz.RPCCapability()
    • authz.RPCCapability({})
  • init

    • authz.RPCCapability("id.rpc2")
  • display

    • authz.RPCCapability("id.rpc1") -> RPCCapability(resource='id.rpc1', param_restrictions={})
    • authz.RPCCapability("id.rpc1", {"k1": "v1"}) -> RPCCapability(resource='id.rpc1', param_restrictions={'k1': 'v1'})
    • authz.RPCCapability("id.rpc1", {"k1": ["v1", "v1a"]}) -> RPCCapability(resource='id.rpc1', param_restrictions={'k1': ['v1', 'v1a']})
  • (optional) display with pre-defined order

    • (i.e., re-ordered the key)
  • obj equal (seems to work)

    • authz.RPCCapability("id.rpc1", {"k2":{}, "k1": ["v1", "v1a"], }) == authz.RPCCapability("id.rpc1", {"k1": ["v1", "v1a"], "k2":{}})
    • negative:
      • authz.RPCCapability("id.rpc1", {"k1": ["v1", "v1a"], "k2":[]}) = authz.RPCCapability("id.rpc1", {"k1": ["v1", "v1a"], "k2":{}})
    • Note: this is releated to the dict key merged and ordered logic
  • add (partially broken)

    • see merge case below

    • merge: (partially broken)

      • TODO: fix the following:
        rpc_cap4 = authz.RPCCapability("id2.rpc2")
        rpc_cap4.add_param_restrictions("p2", "v2")
        rpc_cap4.add_param_restrictions("p2", "v3")
        
        >> current: rpc_cap4 -> RPCCapability(resource='id2.rpc2', param_restrictions={'p2': 'v3'})
        >> expected: rpc_cap4 -> RPCCapability(resource='id2.rpc2', param_restrictions={'p2': ['v2', "v3"]})
        
    • duplicate mechanism

      • To achieve:
        rpc_cap4 = authz.RPCCapability("id2.rpc2")
        rpc_cap4.add_param_restrictions("p2", "v2")
        rpc_cap4.add_param_restrictions("p2", "v2")
        
        >> expected: rpc_cap4 -> RPCCapability(resource='id2.rpc2', param_restrictions={'p2': 'v2'})
        
    • Note: should we allow immutable-fashioned add_rpc_capability, i.e., authz.RPCCapabilities().add_rpc_capability(authz.RPCCapability("id.rpc1")) == authz.RPCCapabilities([authz.RPCCapability("id.rpc1")])

  • remove

    • Definition needed: do we allow remove parameter, value-of-parameter, or the whole resource.
      • no implementation for remove (e.g., remove_param_restrictions)
    • potential behavior, assusimg rpc_cap4 -> RPCCapability(resource='id2.rpc2', param_restrictions={'p2': ['v2', "v3"]})
      • not allow remove reource
        • assert error for rpc_cap4.remove_param_restrictions("id2.rpc2")
      • remove by para rpc_cap4.remove_param_restrictions("p2")
      • remove by para-value rpc_cap4.remove_param_restrictions("v2")
    • implement immutable assignment
  • doc-string

list of tests for authz.RPCCapabilities

  • data class definition
    • Note: TODO: discussion: type of dict in _rpc_dict = field(type=dict, default=None, init=False) can be more rigid, i.e., Dict[str, Dict[str, List[str]]], e.g. _rpc_dict={'id.rpc1': {}, 'id2.rpc2': {'p2': 'v2'}}
  • init (empty init)
    • assert authz.RPCCapabilities()
  • init (init with lists)
    • assert authz.RPCCapabilities([authz.RPCCapability("id.rpc1"), authz.RPCCapability("id.rpc2")])
    • assert authz.RPCCapabilities([])
    • negagive:
      • assert authz.RPCCapabilities(32)
      • assert authz.RPCCapabilities([32])
  • display
    • authz.RPCCapabilities() -> RPCCapabilities(rpc_capabilities=[], _rpc_dict={})
    • authz.RPCCapabilities([authz.RPCCapability("id.rpc1")]) -> RPCCapabilities(rpc_capabilities=[RPCCapability(resource='id.rpc1', param_restrictions={})], _rpc_dict={'id.rpc1': {}})
  • (optional) display with pre-defined order
    • (i.e., re-ordered the key)
  • obj equal (paritially broken)
    • authz.RPCCapabilities([authz.RPCCapability("id.rpc1"), authz.RPCCapability("id2.rpc2")]) == authz.RPCCapabilities([authz.RPCCapability("id2.rpc2"), authz.RPCCapability("id.rpc1")])
    • Note: this is releated to the dict key merged and ordered logic
  • add
    • x = authz.RPCCapabilities(); x.add_rpc_capability(authz.RPCCapability("id.rpc1")); x == authz.RPCCapabilities([authz.RPCCapability("id.rpc1")])
    • Note: should we allow immutable-fashioned add_rpc_capability, i.e., authz.RPCCapabilities().add_rpc_capability(authz.RPCCapability("id.rpc1")) == authz.RPCCapabilities([authz.RPCCapability("id.rpc1")])
    • merge:
      • x = authz.RPCCapabilities(); x.add_rpc_capability(authz.RPCCapability("id.rpc1")); x.add_rpc_capability(authz.RPCCapability("id.rpc2")); x == authz.RPCCapabilities([authz.RPCCapability("id.rpc1"), authz.RPCCapability("id.rpc2")])
    • duplicate mechanism
      • x = authz.RPCCapabilities(); x.add_rpc_capability(authz.RPCCapability("id.rpc1")); x.add_rpc_capability(authz.RPCCapability("id.rpc1")); x == authz.RPCCapabilities([authz.RPCCapability("id.rpc1")])
      • Note: should we give warning when attempting to add duplicate authz.RPCCapability
  • remove
    • remove by capability "key" (i.e., <id.method>)
      • x = authz.RPCCapabilities([authz.RPCCapability("id.rpc1"), authz.RPCCapability("id2.rpc2"), authz.RPCCapability("id3.rpc3", {"p1": "v1"})]); x.remove_rpc_capability(authz.RPCCapability("id2.rpc2")); x = RPCCapabilities(rpc_capabilities=[RPCCapability(resource='id.rpc1', param_restrictions={}), RPCCapability(resource='id3.rpc3', param_restrictions={'p1': 'v1'})], _rpc_dict={'id.rpc1': {}, 'id3.rpc3': {'p1': 'v1'}})
    • remove by capability "key" and para-info
      • x = authz.RPCCapabilities([authz.RPCCapability("id.rpc1"), authz.RPCCapability("id2.rpc2"), authz.RPCCapability("id3.rpc3", {"p1": "v1", "p2": "v2"})]); x.remove_rpc_capability(authz.RPCCapability("id3.rpc3", {"p1": "v1"})); x = RPCCapabilities(rpc_capabilities=[RPCCapability(resource='id.rpc1', param_restrictions={}), RPCCapability(resource='id2.rpc2', param_restrictions={}), RPCCapability(resource='id2.rpc2', param_restrictions={'p2': 'v2'})], _rpc_dict={'id.rpc1': {}, 'id2.rpc2': {'p2': 'v2'}})
    • Note: partially broken due to equal (==) not working/defined
      x = authz.RPCCapabilities([authz.RPCCapability("id.rpc1"), authz.RPCCapability("id2.rpc2"), authz.RPCCapability("id2.rpc2", {"p1": "v1"})]) 
      x.remove_rpc_capability(authz.RPCCapability("id2.rpc2"))
      * expected x = RPCCapabilities(rpc_capabilities=[RPCCapability(resource='id.rpc1', param_restrictions={})], _rpc_dict={'id.rpc1': {}})
      * currently x = RPCCapabilities(rpc_capabilities=[RPCCapability(resource='id.rpc1', param_restrictions={}), RPCCapability(resource='id2.rpc2', param_restrictions={'p1': 'v1'})], _rpc_dict={'id.rpc1': {}})
      
    • Note: should we allow immutable-fashioned assignment:
      • i.e., authz.RPCCapabilities([authz.RPCCapability("id.rpc1"), authz.RPCCapability("id2.rpc2"),]).remove_rpc_capability(authz.RPCCapability("id2.rpc2")) = authz.RPCCapabilities([authz.RPCCapability("id.rpc1")])
  • docstring
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@kefeimo and others