-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #85 from matrix-org/kegan/reject-app-versions
Add support for blocking specific app/version/label combinations
- Loading branch information
Showing
5 changed files
with
233 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Add support for blocking specific app/version/label combinations. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
package main | ||
|
||
import "testing" | ||
|
||
func TestConfigRejectionCondition(t *testing.T) { | ||
cfg := config{ | ||
RejectionConditions: []RejectionCondition{ | ||
{ | ||
App: "my-app", | ||
Version: "0.1.0", | ||
}, | ||
{ | ||
App: "my-app", | ||
Label: "0.1.1", | ||
}, | ||
{ | ||
App: "my-app", | ||
Version: "0.1.2", | ||
Label: "nightly", | ||
}, | ||
{ | ||
App: "block-my-app", | ||
}, | ||
}, | ||
} | ||
rejectPayloads := []payload{ | ||
{ | ||
AppName: "my-app", | ||
Data: map[string]string{ | ||
"Version": "0.1.0", | ||
}, | ||
}, | ||
{ | ||
AppName: "my-app", | ||
Data: map[string]string{}, | ||
Labels: []string{"0.1.1"}, | ||
}, | ||
{ | ||
AppName: "my-app", | ||
Labels: []string{"foo", "nightly"}, | ||
Data: map[string]string{ | ||
"Version": "0.1.2", | ||
}, | ||
}, | ||
{ | ||
AppName: "block-my-app", | ||
}, | ||
{ | ||
AppName: "block-my-app", | ||
Labels: []string{"foo"}, | ||
}, | ||
{ | ||
AppName: "block-my-app", | ||
Data: map[string]string{ | ||
"Version": "42", | ||
}, | ||
}, | ||
{ | ||
AppName: "block-my-app", | ||
Labels: []string{"foo"}, | ||
Data: map[string]string{ | ||
"Version": "42", | ||
}, | ||
}, | ||
} | ||
for _, p := range rejectPayloads { | ||
if !cfg.matchesRejectionCondition(&p) { | ||
t.Errorf("payload was accepted when it should be rejected:\n payload=%+v\nconfig=%+v", p, cfg) | ||
} | ||
} | ||
acceptPayloads := []payload{ | ||
{ | ||
AppName: "different-app", | ||
Data: map[string]string{ | ||
"Version": "0.1.0", | ||
}, | ||
}, | ||
{ | ||
AppName: "different-app", | ||
Data: map[string]string{}, | ||
Labels: []string{"0.1.1"}, | ||
}, | ||
{ | ||
AppName: "different-app", | ||
Labels: []string{"foo", "nightly"}, | ||
Data: map[string]string{ | ||
"Version": "0.1.2", | ||
}, | ||
}, | ||
{ | ||
AppName: "my-app", | ||
Data: map[string]string{ | ||
"Version": "0.1.0-suffix", | ||
}, | ||
}, | ||
{ | ||
AppName: "my-app", | ||
Data: map[string]string{}, | ||
Labels: []string{"0.1.1-suffix"}, | ||
}, | ||
{ | ||
AppName: "my-app", | ||
Labels: []string{"foo", "nightly-suffix"}, | ||
Data: map[string]string{ | ||
"Version": "0.1.2", | ||
}, | ||
}, | ||
{ // version matches but label does not (it's Label AND Version not OR) | ||
AppName: "my-app", | ||
Labels: []string{"foo"}, | ||
Data: map[string]string{ | ||
"Version": "0.1.2", | ||
}, | ||
}, | ||
} | ||
for _, p := range acceptPayloads { | ||
if cfg.matchesRejectionCondition(&p) { | ||
t.Errorf("payload was rejected when it should be accepted:\n payload=%+v\nconfig=%+v", p, cfg) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters