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

Allow group 0 to be created by provisioning API #29712

Merged
merged 1 commit into from
Dec 1, 2017

Conversation

phil-davis
Copy link
Contributor

@phil-davis phil-davis commented Nov 29, 2017

Description

Only the empty string should be rejected as a group name (or things that == the empty string such as null and false). This lets "0" be created as a group name.

Related Issue

#29698

Motivation and Context

Zero and empty must not live in the same house.

How Has This Been Tested?

The new integration test fails before and passes after this fix.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

individual-it
individual-it previously approved these changes Nov 29, 2017
@codecov
Copy link

codecov bot commented Nov 29, 2017

Codecov Report

Merging #29712 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master   #29712   +/-   ##
=========================================
  Coverage     62.49%   62.49%           
- Complexity    17619    17621    +2     
=========================================
  Files          1045     1045           
  Lines         58070    58070           
=========================================
  Hits          36288    36288           
  Misses        21782    21782
Impacted Files Coverage Δ Complexity Δ
apps/provisioning_api/lib/Groups.php 100% <100%> (ø) 23 <0> (+2) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 17f398b...6b7b87c. Read the comment docs.

@@ -130,7 +130,7 @@ public function getGroup($parameters) {
public function addGroup($parameters) {
// Validate name
$groupId = $this->request->getParam('groupid', '');
if(empty($groupId)){
if($groupId == ''){
Copy link
Contributor

Choose a reason for hiding this comment

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

classic

Copy link
Contributor

Choose a reason for hiding this comment

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

can you make that === ? because == might also match null values. If we also want to check for nulll values, also add is_null($groupId)

Copy link
Contributor Author

@phil-davis phil-davis Nov 29, 2017

Choose a reason for hiding this comment

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

I wanted to match all of:

if ($group === "")
if (is_null($group))
if ($group === false)

and those 3 things all are done in 1 statement by:

if ($group == "")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In theory the return value of getParam is always a string - it "should" never be null or false, but who knows.

Copy link
Member

Choose a reason for hiding this comment

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

you could check if $group is a string and if not also show the same error. Or even throw an exception because if the the group name is not a string something went terrible wrong.

Copy link
Contributor Author

@phil-davis phil-davis Nov 30, 2017

Choose a reason for hiding this comment

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

Way too much time spent on a 1-line fix. Somebody tell me what code will be accepted for review and then I can write that. Otherwise I will just be guessing what is wanted and going round-and-round the long CI process.

@individual-it
Copy link
Member

Why is Jenkins failing? Do the Scenarios depend on each other?

@phil-davis
Copy link
Contributor Author

phil-davis commented Nov 29, 2017

Yes, it does not look ideal - groups that are created by when sending POST to "/cloud/groups" are not deleted after each scenario so they "add up". It means that some scenarios cannot be run just by themselves. So I will need to do some work to sort that out.

(creating users has the same issue)

@@ -140,13 +150,16 @@ Feature: provisioning

Scenario: Getting all groups
Given as an "admin"
And group "0" exists
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I "fixed up" this test so that at least it explicitly specifies each group to exists then checks that they are returned by the /cloud/groups endpoint.
Actually each group (except admin) is created in one of the previous scenarios by code that does:

When sending "POST" to "/cloud/groups" with

That step does not "remember" that it created a group, because that is a generic step for "driving the API". So in those kind of scenarios, the created group is not deleted by the AfterScenario code.

Thus this scenario would actually pass without specifically needing to mention that the 4 groups "exist".

Creating users has the same problem - various scenarios create users that are not deleted in the AfterScenario code. But all that sort of thing needs to be looked at separately, otherwise this "little" PR will become "bigger than Ben Hur" if it starts rectifying existing "features" of the test infrastructure.

@phil-davis phil-davis dismissed individual-it’s stale review November 30, 2017 01:54

Changes since original review - please review again.

@@ -130,7 +130,7 @@ public function getGroup($parameters) {
public function addGroup($parameters) {
// Validate name
$groupId = $this->request->getParam('groupid', '');
if(empty($groupId)){
if(($groupId === '') || is_null($groupId) || ($groupId === false)){
Copy link
Contributor Author

@phil-davis phil-davis Nov 30, 2017

Choose a reason for hiding this comment

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

@PVince81 I went for the full list here - empty() essentially means "blank or null or false or 0 or '0'". We want 0 or '0' to be allowed and the others can continue to be banned as a group name.

@phil-davis
Copy link
Contributor Author

Backport stable10 #29734

@lock
Copy link

lock bot commented Aug 1, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Aug 1, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants