-
Notifications
You must be signed in to change notification settings - Fork 111
[OSJC-157] Throw unauthorized exception when a 403 status is returned #10
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
24 changes: 24 additions & 0 deletions
24
src/main/java/com/openshift/restclient/http/IHttpStatusCodes.java
This file contains hidden or 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,24 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2015 Red Hat, Inc. Distributed under license by Red Hat, Inc. | ||
* All rights reserved. This program is made available under the terms of the | ||
* Eclipse Public License v1.0 which accompanies this distribution, and is | ||
* available at http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: Red Hat, Inc. - initial API and implementation | ||
******************************************************************************/ | ||
package com.openshift.restclient.http; | ||
|
||
/** | ||
* HTTP Status codes | ||
* @author jeff.cantrill | ||
* | ||
*/ | ||
public interface IHttpStatusCodes { | ||
|
||
public static final int STATUS_OK = 200; | ||
public static final int STATUS_INTERNAL_SERVER_ERROR = 500; | ||
public static final int STATUS_BAD_REQUEST = 400; | ||
public static final int STATUS_UNAUTHORIZED = 401; | ||
public static final int STATUS_FORBIDDEN = 403; | ||
public static final int STATUS_NOT_FOUND = 404; | ||
} |
This file contains hidden or 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
48 changes: 48 additions & 0 deletions
48
src/test/java/com/openshift/internal/restclient/model/V1Beta3StatusTest.java
This file contains hidden or 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,48 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2015 Red Hat, Inc. Distributed under license by Red Hat, Inc. | ||
* All rights reserved. This program is made available under the terms of the | ||
* Eclipse Public License v1.0 which accompanies this distribution, and is | ||
* available at http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: Red Hat, Inc. | ||
******************************************************************************/ | ||
package com.openshift.internal.restclient.model; | ||
|
||
import static org.junit.Assert.*; | ||
import static org.mockito.Mockito.*; | ||
|
||
import org.jboss.dmr.ModelNode; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
|
||
import com.openshift.internal.restclient.model.properties.ResourcePropertiesRegistry; | ||
import com.openshift.restclient.IClient; | ||
import com.openshift.restclient.ResourceKind; | ||
import com.openshift.restclient.model.IStatus; | ||
import com.openshift.restclient.utils.Samples; | ||
|
||
/** | ||
* Test to validate the lookup paths are correct for the version | ||
* @author Jeff Cantrill | ||
*/ | ||
public class V1Beta3StatusTest{ | ||
|
||
private static IStatus status; | ||
|
||
@BeforeClass | ||
public static void setUp(){ | ||
IClient client = mock(IClient.class); | ||
ModelNode node = ModelNode.fromJSONString(Samples.V1BETA3_Status.getContentAsString()); | ||
status = new Status(node, client, ResourcePropertiesRegistry.getInstance().get("v1beta3", ResourceKind.Status)); | ||
} | ||
|
||
@Test | ||
public void testGetMessage() { | ||
assertEquals("\"/api/v1beta1/services/ruby-helloworld-sample\" is forbidden because foo cannot get on services with name \"ruby-helloworld-sample\" in default", status.getMessage()); | ||
} | ||
|
||
@Test | ||
public void testGetCode() { | ||
assertEquals(403, status.getCode()); | ||
} | ||
} |
This file contains hidden or 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 hidden or 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,10 @@ | ||
{ | ||
"kind": "Status", | ||
"apiVersion": "v1beta3", | ||
"metadata": {}, | ||
"status": "Failure", | ||
"message": "\"/api/v1beta1/services/ruby-helloworld-sample\" is forbidden because foo cannot get on services with name \"ruby-helloworld-sample\" in default", | ||
"reason": "Forbidden", | ||
"details": {}, | ||
"code": 403 | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am pretty convinced that using an enum for api version is not the right tool at hand. Enums typically are the right tool for closed exhaustive choice whereas in API versions we clearly have an open ended choice. I would clearly switch to a class and move away from enum.