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

Add a "validate" argument option to JSONSerializer #1775

Merged

Commits on Feb 28, 2022

  1. Add __eq__ to classes in Metadata API

    By adding __eq__ we can compare that two objects are equal.
    That will be useful when adding validation API call.
    
    One bug I have found during testing is that I don't check if the type
    of "other" in the __eq__ implementations are the expected ones.
    I assumed that when comparing "root == obj" if "obj" is None that
    automatically the result will be false.
    Later after a mypy warning, I realized we should implement the __eq__
    methods to accept "Any" type as other and we should check manually
    that "other" is the expected type.
    
    Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
    MVrachev committed Feb 28, 2022
    Configuration menu
    Copy the full SHA
    30a707c View commit details
    Browse the repository at this point in the history
  2. Test __eq__ implementation for all classes

    Test the "__eq__" implementation for all classes defined in
    tuf/api/metadata.py
    The tests are many but simple. The idea is to test each of the metadata
    classes one by one and with this to make sure there are no possible
    cases missed.
    
    Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
    MVrachev committed Feb 28, 2022
    Configuration menu
    Copy the full SHA
    5d24956 View commit details
    Browse the repository at this point in the history
  3. Add "validation" arg in JSONSerializer

    If the "validation" argument is set then when
    serializing the metadata object will be validated.
    
    Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
    MVrachev committed Feb 28, 2022
    Configuration menu
    Copy the full SHA
    a17ceda View commit details
    Browse the repository at this point in the history
  4. Take order into account for certain cases

    After we have dropped OrderedDict in theupdateframework@e3b267e
    we are relying on python3.7+ default behavior to preserve the insertion
    order, but there is one caveat.
    When comparing dictionaries the order is still irrelevant compared to
    OrderedDict. For example:
    >>> OrderedDict([(1,1), (2,2)]) == OrderedDict([(2,2), (1,1)])
    False
    >>> dict([(1,1), (2,2)]) == dict([(2,2), (1,1)])
    True
    
    There are two special attributes, defined in the specification, where
    the order makes a difference when comparing two objects:
    - Metadata.signatures
    - Targets.delegations.roles.
    We want to make sure that the order in those two cases makes a
    difference when comparing two objects and that's why those changes
    are required inside two __eq__ implementations.
    
    Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
    MVrachev committed Feb 28, 2022
    Configuration menu
    Copy the full SHA
    6ea5372 View commit details
    Browse the repository at this point in the history