Beispiel #1
0
def test_validate_ota_image_simple_valid():
    image = OTAImage()
    image.subelements = [
        create_subelement(ElementTagId.UPGRADE_IMAGE, VALID_EBL_IMAGE),
    ]

    assert validators.validate_ota_image(image) == ValidationResult.VALID
Beispiel #2
0
def test_validate_ota_image_mixed_valid():
    image = OTAImage()
    image.subelements = [
        create_subelement(ElementTagId.UPGRADE_IMAGE, b"unknown1"),
        create_subelement(ElementTagId.UPGRADE_IMAGE, VALID_EBL_IMAGE),
    ]

    assert validators.validate_ota_image(image) == ValidationResult.UNKNOWN
Beispiel #3
0
def test_validate_ota_image_invalid():
    image = OTAImage()
    image.subelements = [
        create_subelement(ElementTagId.UPGRADE_IMAGE, VALID_EBL_IMAGE[:-1]),
    ]

    with pytest.raises(ValidationError):
        validators.validate_ota_image(image)
Beispiel #4
0
def test_validate_ota_image_complex_valid():
    image = OTAImage()
    image.subelements = [
        create_subelement(ElementTagId.ECDSA_SIGNATURE, b"asd"),
        create_subelement(ElementTagId.UPGRADE_IMAGE, VALID_EBL_IMAGE),
        create_subelement(ElementTagId.UPGRADE_IMAGE, VALID_GBL_IMAGE),
        create_subelement(ElementTagId.ECDSA_SIGNING_CERTIFICATE, b"foo"),
    ]

    assert validators.validate_ota_image(image) == ValidationResult.VALID
Beispiel #5
0
def test_check_invalid():
    image = OTAImage()

    with mock.patch("zigpy.ota.validators.validate_ota_image") as m:
        m.side_effect = [ValidationResult.VALID]
        assert not validators.check_invalid(image)

    with mock.patch("zigpy.ota.validators.validate_ota_image") as m:
        m.side_effect = [ValidationResult.UNKNOWN]
        assert not validators.check_invalid(image)

    with mock.patch("zigpy.ota.validators.validate_ota_image") as m:
        m.side_effect = [ValidationError("error")]
        assert validators.check_invalid(image)
Beispiel #6
0
def test_validate_ota_image_empty():
    image = OTAImage()

    assert validators.validate_ota_image(image) == ValidationResult.UNKNOWN
Beispiel #7
0
def test_validate_ota_image_empty():
    image = OTAImage()
    image.subelements = []

    assert validators.validate_ota_image(image) == ValidationResult.UNKNOWN