Skip to content

Commit

Permalink
Do not leak "private" fields into export
Browse files Browse the repository at this point in the history
Fields starting with underscore, `_`, are considered "private" and
should not be exported.

This is a "dirty" workaround to fix #1729, a proper fix would probably
turn the table around, and instead of hiding some fields it would export
only fields marked for export. That should be implemented later for #1688.

Fixes #1729.
  • Loading branch information
happz committed Dec 6, 2022
1 parent 278115a commit 55e3837
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 0 deletions.
6 changes: 6 additions & 0 deletions tests/plan/export/data/plan.fmf
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,9 @@ execute:
- merge-pull-request
- add-build-to-update
- add-build-to-compose

/remote:
plan:
import:
url: https://github.com/teemtee/tmt
name: /plans/features/basic
5 changes: 5 additions & 0 deletions tests/plan/export/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ rlJournalStart
rlAssertGrep "- name: /plan/gate" $rlRun_LOG
rlAssertGrep "discover:" $rlRun_LOG
rlAssertGrep "execute:" $rlRun_LOG
rlAssertNotGrep " _" $rlRun_LOG
rlPhaseEnd

rlPhaseStartTest "tmt plan export /plan/basic"
Expand All @@ -24,6 +25,7 @@ rlJournalStart
rlAssertGrep "summary: Just basic keys." $rlRun_LOG
rlAssertGrep "discover:" $rlRun_LOG
rlAssertGrep "execute:" $rlRun_LOG
rlAssertNotGrep " _" $rlRun_LOG
rlPhaseEnd

rlPhaseStartTest "tmt plan export /plan/context"
Expand All @@ -34,6 +36,7 @@ rlJournalStart
rlAssertGrep "execute:" $rlRun_LOG
rlAssertGrep "context:" $rlRun_LOG
rlAssertGrep "component: dash" $rlRun_LOG
rlAssertNotGrep " _" $rlRun_LOG
rlPhaseEnd

rlPhaseStartTest "tmt plan export /plan/environment"
Expand All @@ -44,6 +47,7 @@ rlJournalStart
rlAssertGrep "execute:" $rlRun_LOG
rlAssertGrep "environment:" $rlRun_LOG
rlAssertGrep "RELEASE: f35" $rlRun_LOG
rlAssertNotGrep " _" $rlRun_LOG
rlPhaseEnd

rlPhaseStartTest "tmt plan export /plan/gate"
Expand All @@ -56,6 +60,7 @@ rlJournalStart
rlAssertGrep "- merge-pull-request" $rlRun_LOG
rlAssertGrep "- add-build-to-update" $rlRun_LOG
rlAssertGrep "- add-build-to-compose" $rlRun_LOG
rlAssertNotGrep " _" $rlRun_LOG
rlPhaseEnd

rlPhaseStartTest "Invalid format"
Expand Down
2 changes: 2 additions & 0 deletions tests/story/export/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ rlJournalStart
rlAssertGrep "name: /mini" $rlRun_LOG
rlAssertGrep "order: 50" $rlRun_LOG
rlAssertGrep "story: As a user I want this and that" $rlRun_LOG
rlAssertNotGrep " _" $rlRun_LOG
rlPhaseEnd

rlPhaseStartTest "Export to yaml (full story)"
Expand All @@ -25,6 +26,7 @@ rlJournalStart
rlAssertGrep "story: As a user I want this and that" $rlRun_LOG
rlAssertGrep "title: A Concise Title" $rlRun_LOG
rlAssertGrep "priority: must have" $rlRun_LOG
rlAssertNotGrep " _" $rlRun_LOG
rlRun "grep -A1 ^link: $rlRun_LOG | grep -- ' - implemented-by: /some/code.py'"
rlRun "grep -A1 ^tag: $rlRun_LOG | grep -- '- foo'"
rlRun "grep -A1 ^example: $rlRun_LOG | grep -- '- An inspiring example'"
Expand Down
4 changes: 4 additions & 0 deletions tests/test/export/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ rlJournalStart
rlPhaseStartTest "$cmd"
rlRun -s "$cmd" 0 "Export test"
rlAssertGrep "'name': '$tname'" $rlRun_LOG
rlAssertNotGrep "'_" $rlRun_LOG
rlPhaseEnd

cmd="tmt tests export --format yaml $tname"
rlPhaseStartTest "$cmd"
rlRun -s "$cmd" 0 "Export test"
rlAssertGrep "name: $tname" $rlRun_LOG
rlAssertNotGrep " _" $rlRun_LOG
rlPhaseEnd
done

Expand Down Expand Up @@ -61,12 +63,14 @@ rlJournalStart
rlPhaseStartTest "$cmd"
rlRun -s "$cmd" 0 "Export test"
rlAssertGrep "'name': '$tname'" $rlRun_LOG
rlAssertNotGrep "'_" $rlRun_LOG
rlPhaseEnd

cmd="tmt tests export --format yaml --fmf-id $tname"
rlPhaseStartTest "$cmd"
rlRun -s "$cmd" 0 "Export test"
rlAssertGrep "name: $tname" $rlRun_LOG
rlAssertNotGrep " _" $rlRun_LOG
rlPhaseEnd
done

Expand Down
6 changes: 6 additions & 0 deletions tmt/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,12 @@ def export(self, *, format_: ExportFormat = ExportFormat.YAML,
# Always include node name, add requested keys, ignore adjust
data: Dict[str, Any] = dict(name=self.name)
for key in keys:
# TODO: provide more mature solution for https://github.com/teemtee/tmt/issues/1688
# Untile that, do not export fields that start with an underscore, to avoid leaking
# "private" object members.
if key.startswith('_'):
continue

if key == 'adjust':
continue

Expand Down

0 comments on commit 55e3837

Please sign in to comment.