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 simple tests for yamlprobe #1479

Merged
merged 11 commits into from
Feb 18, 2020

Conversation

yuumasato
Copy link
Member

Description

  • Add a few simple tests using yamlfilecontent_test to exercise not-yet-existing yamlfileprobe (time to TDD).

@yuumasato
Copy link
Member Author

@evgenyz @matejak I'd appreciate any feedback on the tests and the direction it is going.

<ind-def:yamlfilecontent_object version="1" id="oval:0:obj:1">
<ind-def:path>/tmp</ind-def:path>
<ind-def:filename>openshift-logging.yaml</ind-def:filename>
<ind-def:yamlpath>/kind</ind-def:yamlpath>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Current YAML Path definition is here: https://github.com/evgenyz/libyaml-yamlpath-filter/wiki/YAML-Path-(OVAL-subset). It became even smaller; for now there are only keys, indexes and slices (for lists, not for maps). And only dot notation (to be more compatible with JSONPath).

You can get the idea of what it is capable of right now here: https://github.com/evgenyz/libyaml-yamlpath-filter/blob/afb1fec90a5eb3974d1115bab1d1bfff4956b91a/test-paths.c#L170.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for now there are only keys, indexes and slices (for lists, not for maps).

I'm not sure if array slicing will be that useful. Can we be sure of the order of the items in a list?

So hash key searching is not supported? 😢
I think key searching will be the most useful feature.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a case already for slices (which could be used as any filter for sequences), in the example we have we are looking for at least one record of certain type. The path is .spec.pipelines[:].inputSource and result would be ['logs.app', 'logs.infra', 'logs.audit']. We are after logs.audit.

Copy link
Contributor

@evgenyz evgenyz Feb 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Key searching is another thing. You can address anything by an exact key. But there is no fuzzy key search of any kind right now. Until we prove it to be useful. I try to keep it as dumb as possible to actually have all the logic in OVAL territory.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we be sure of the order of the items in a list?

Yes, it'd be the same as in the document.

Copy link
Member Author

@yuumasato yuumasato Feb 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets just stick to what we have right now, and evolve with the content, should the need arise.

I understand, we need to start writing content as soon as possible then, to collect use cases, even when the probe is not ready.

But I want to be sure that workaround is ugly enough or impossible before starting to deal with all the problems related to [XXX=YYY].

At the same time, one of the goals of the probe is to avoid need for workarounds or complex OVAL contents.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@evgeni Apologies, 😮

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the same time, one of the goals of the probe is to avoid need for workarounds or complex OVAL contents.

Balance. That is what we usually looking for :)

I understand, we need to start writing content as soon as possible then, to collect use cases, even when the probe is not ready.

Exactly. So I'm trying to create something to give our OCP colleagues tools to start working and pinpointing weak spots.

Is the python style slicing syntax specific to libyaml-yamlpath-fitler?
yaml-get doesn't like it.

Yes, it is. And it is how things are done in JSONPath. I don't like YAML Paths' version because you can't collect the whole list with it.

YAML Paths' '.spec.pipelines.inputSource' is too ambiguous. It completely skips the list in the middle, inputSource may as well be just a key in pipelines dictionary, which is not acceptable at all. It is so because YAML Path uses so called arrays pass-through, which is not good from a security-related tool point of view, IMHO.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, if you want to play with our (he-he) YAML Path, go ahead: https://github.com/OpenSCAP/yaml-filter. We even have a console tool now :)

@evgenyz
Copy link
Contributor

evgenyz commented Feb 15, 2020

I feel like you overdoing this right now. We have unit tests for YAML Path behaviour in the library. We are after the probe integration tests: no results, 1 result, multiple results, errors (no file, invalid path, path pointing to a non-scalar value).

Copy link
Member

@jan-cerny jan-cerny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we have a perfect testing OVAL content now, but we should also check that probe collects the data from the YAML file.

<ind-def:state state_ref="oval:0:ste:2"/>
</ind-def:yamlfilecontent_test>

<ind-def:yamlfilecontent_test version="1" id="oval:0:tst:3" check="all" comment="error">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is error expected?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK


rm -f $YAML_FILE

return $ret_val
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where do you test that the correct data was extracted from the YAML? Please add assertions on collected items.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests have states, if they pass doesn't it mean we have collected the correct data?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably yes

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about the that expected error result? And what about that non-existing scalar? The test could assume that no objects are collected.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per yamlpath description in https://github.com/OVAL-Community/OVAL/pull/90/files#diff-ae56180beddebc6013e4387e9ed9fe0eR2118, error is the expected result when the path leads to a non-scalar.

The xpath field in xmlfilecontent_object behaves the same way.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, maybe @matejak is asking about how the test verifies that the result was error?
In verify_results() the result of evaluation is compared with the results the comments.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I was not able to understand just by looking at verify_results documentation. That doc needs a refresh.

@yuumasato
Copy link
Member Author

I feel like you overdoing this right now.

I think we have a perfect testing OVAL content now,

😃

We have unit tests for YAML Path behaviour in the library. We are after the probe integration tests: no results, 1 result, multiple results, errors (no file, invalid path, path pointing to a non-scalar value).

@evgenyz I don't understand what you are missing.
I believe these work as integration tests, and most of what you mention is already covered.

@matejak
Copy link
Contributor

matejak commented Feb 17, 2020

@evgenyz I don't understand what you are missing.
I believe these work as integration tests, and most of what you mention is already covered.

I think that Evgeny is not happy with the library being tested twice - once in respective unit-tests and basically once by analysing OVAL results produced by the probe that uses the library.
I am not against this "double testing", as I find it as an appropriate "black box" testing of the probe.

<ind-def:yamlfilecontent_object version="1" id="oval:0:obj:5">
<ind-def:path>/tmp</ind-def:path>
<ind-def:filename>yaml-filter.yaml</ind-def:filename>
<ind-def:yamlpath>.foo[1].some\.el\/here</ind-def:yamlpath>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test yaml file modification is needed in order for this to pass, right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually back-slash escaping is not supported so far. This won't work no matter what, ATM.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@evgenyz Do we expect to support it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test yaml file modification is needed in order for this to pass, right?

I forgot to add yaml-filter.yaml into the commit.
But I'll drop the commit for now.

Copy link
Contributor

@evgenyz evgenyz Feb 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we expect. Working on it. But you'd better not include it in this PR. (Edit: Actually it could be a bit different)

@evgenyz
Copy link
Contributor

evgenyz commented Feb 17, 2020

@evgenyz I don't understand what you are missing.
I believe these work as integration tests, and most of what you mention is already covered.

I think that Evgeny is not happy with the library being tested twice - once in respective unit-tests and basically once by analysing OVAL results produced by the probe that uses the library.

Yeah, I'm grumbling about excessive tests, not because something is missing. While excessive test might be seemed as a neutral or even a positive feature, one should always keep in mind that there is a toll of test maintenance (and execution time, BTW) in a developing library (such as libyamlpath) and usually there are no gains from this duplicity.

@yuumasato yuumasato force-pushed the add-yamlfilecontent-test branch from 8231672 to d54d078 Compare February 18, 2020 12:24
@yuumasato
Copy link
Member Author

Yeah, I'm grumbling about excessive tests, not because something is missing. While excessive test might be seemed as a neutral or even a positive feature, one should always keep in mind that there is a toll of test maintenance (and execution time, BTW) in a developing library (such as libyamlpath) and usually there are no gains from this duplicity.

I'm happy to remove anything that is excessive and duplicate.
But just like Matěj, I see these as black box tests for the probe. They will define expected behavior of the probe and how content would look like. They are not focused in finding bugs in yaml-filter.
CC: @matusmarhefka, maybe you have opinions ^

@yuumasato
Copy link
Member Author

Per #1479 (comment) I've dropped escaped key test: b61d5f9

@yuumasato
Copy link
Member Author

I was going to add tests for anchor, but @evgenyz said it is not implemented yet.

So this should be good to merge, if reviewers are ok.

@yuumasato yuumasato marked this pull request as ready for review February 18, 2020 12:48
@jan-cerny
Copy link
Member

I'm fine.

@evgenyz
Copy link
Contributor

evgenyz commented Feb 18, 2020

I'm fine.

But it's your request for changes still active :)

@evgenyz
Copy link
Contributor

evgenyz commented Feb 18, 2020

I'm fine with this PR, don't take my whining about excessiveness as a blocker

@evgenyz evgenyz merged commit 97a19ac into OpenSCAP:maint-1.3 Feb 18, 2020
@yuumasato yuumasato deleted the add-yamlfilecontent-test branch February 18, 2020 14:19
@yuumasato yuumasato added this to the 1.3.3 milestone Feb 18, 2020
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

Successfully merging this pull request may close these issues.

5 participants