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

Gitea drone #28

Merged
merged 37 commits into from
May 6, 2021
Merged

Gitea drone #28

merged 37 commits into from
May 6, 2021

Conversation

Dunky13
Copy link
Contributor

@Dunky13 Dunky13 commented Mar 30, 2021

Update tasks to allow Gitea to get client ID/Secret for Drone to work/implement with Gitea

Fixes: #26

Marc Went added 15 commits March 18, 2021 21:34
The script checks and compares if there is a secret on the cluster, and whether is matches with the
oauth in Gitea. If it maches, it checks whether authorization for that oauth key is granted, if not
grant it as well. That way human interaction is minimized.

redkubes/unassigned-issues#170, linode/apl-core#364, #26
Renamed class to GiteaDroneOAuth so it is more descriptive

#26
Removed an uncessary else statement

#26
add debug logs to find issue in compiled code

#26
Added more debug logs to find the issue

#26
for some reason the program doesn't want to eat it's cookies, trying to see what's in them that it
doesn't like

#26
Needed to set redirect uri to drone instead of gitea

#26
Found issue (redirect uri), fixed it, now is clean up time

#26
Seems like when oauth is ready, it will follow redirect. Don't want/need that.

#26
values repo was by default public (whoops) - now it's private

redkubes/unassigned-issues#170
package.json Show resolved Hide resolved
src/tasks/gitea/gitea-drone-oauth.ts Outdated Show resolved Hide resolved
src/tasks/gitea/gitea-drone-oauth.ts Outdated Show resolved Hide resolved
src/tasks/gitea/gitea-drone-oauth.ts Outdated Show resolved Hide resolved
src/tasks/gitea/gitea-drone-oauth.ts Outdated Show resolved Hide resolved
src/tasks/gitea/gitea-drone-oauth.ts Outdated Show resolved Hide resolved
src/tasks/gitea/gitea-drone-oauth.ts Outdated Show resolved Hide resolved
src/tasks/gitea/gitea-drone-oauth.ts Outdated Show resolved Hide resolved
src/tasks/gitea/gitea-drone-oauth.ts Outdated Show resolved Hide resolved
src/tasks/gitea/gitea-drone-oauth.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@Morriz Morriz left a comment

Choose a reason for hiding this comment

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

looking good....please rewrite the class to functions and wrap up minor issues...and ship!

package.json Show resolved Hide resolved
src/tasks/gitea/gitea-drone-oauth.ts Outdated Show resolved Hide resolved
src/tasks/gitea/gitea-drone-oauth.ts Outdated Show resolved Hide resolved
src/tasks/gitea/gitea-drone-oauth.ts Outdated Show resolved Hide resolved
src/tasks/gitea/gitea-drone-oauth.ts Outdated Show resolved Hide resolved
src/tasks/gitea/gitea-drone-oauth.ts Outdated Show resolved Hide resolved
src/tasks/gitea/gitea-drone-oauth.ts Outdated Show resolved Hide resolved
Marc Went added 3 commits March 31, 2021 10:54
Clarified error messages, and fixed naming

#26 #28
Create a droneLoginUrl variable, as well as making the csrfToken local, and remove implicit any

#26 #28
_csrf is MVC necessary for authorization & grants of oauth

#26 #28
Copy link
Contributor

@j-zimnowoda j-zimnowoda left a comment

Choose a reason for hiding this comment

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

Could you write some unit tests?

Marc Went added 3 commits March 31, 2021 11:37
Also run the main function, only when executed the script. Don't run it if it is imported. This
messes up unit tests.

#26 #28
@Dunky13
Copy link
Contributor Author

Dunky13 commented Apr 1, 2021

@Morriz and @j-zimnowoda I implemented your suggestions, rewrote part of the script to make it better testable. Hope all is well now?

Use ts-custom-error as a shim for the tests. Make DRONE_URL an env variable. And lazy load apiClient

#26 #28
Copy link
Contributor

@Morriz Morriz left a comment

Choose a reason for hiding this comment

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

Lets see if we can clean this up and move on

Comment on lines 146 to 147
} else if (oauthApps.length == 0) {
console.log("Gitea doesn't have any oauth application defined")
Copy link
Contributor

Choose a reason for hiding this comment

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

Please understand it is WE who add them, so WE are in control. WE can check if one exists and NEVER insert another.

afterEach(() => {
sandbox.restore()
})
it('should successfully validate secret', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

The secret content is validated through typing as a contract. No logic is involved there. No tests should exist therefor.

Can we please move on?

})
})

describe('Gitea-Drone: Parse CSRF Token', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Really? After all my comments you still advocate for useless tests?

})
})

describe('Gitea-Drone: Parse CSRF Token', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

when I say use the force it means you don't come up with it yourself but instead use the powers given to you through open source software. Use micro libraries to avoid inventing a cookie parser.

try {
await axios.request(grantOptions)
} catch (error) {
// Do nothing, error code could be on the redirect
Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, that is fine. Just put these remarks there in the comment to be precise.


export function isSecretValid(remoteSecret: DroneSecret, oauthApps: OAuth2Application[]): boolean {
if (!remoteSecret) {
console.log('Remote secret was not found')
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is null valid?

if (!remoteSecret) {
console.log('Remote secret was not found')
} else if (remoteSecret.clientId.length == 0 || remoteSecret.clientSecret.length == 0) {
console.log('Remote secret values were empty')
Copy link
Contributor

Choose a reason for hiding this comment

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

If we determine that the preconditions have not been met we should just fail.

src/tasks/gitea/gitea-drone-oauth.ts Outdated Show resolved Hide resolved
(x) => x.name === oauthOpts.name,
)
// If secret exists (correctly) and oauth apps are (still) defined, everything is good
if (isSecretValid(remoteSecret, oauthApps)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please read my comments about why I think it should not even exist

@Morriz
Copy link
Contributor

Morriz commented Apr 11, 2021

I would really like to see my remarks implemented and move on with the release of this. Can you please proceed and just remove the tests I deemed invalid?

Copy link
Contributor

@j-zimnowoda j-zimnowoda left a comment

Choose a reason for hiding this comment

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

Marc, you addressed most of the remarks and proved that the code is functional.
Thank you for your hard work.

afterEach(() => {
sandbox.restore()
})
it('should successfully validate secret', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

The typing is static and has nothing to do with code execution

@Morriz Morriz assigned Morriz and unassigned Morriz Apr 15, 2021
Copy link
Contributor

@Morriz Morriz left a comment

Choose a reason for hiding this comment

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

good enough for now

Copy link
Contributor

@j-zimnowoda j-zimnowoda left a comment

Choose a reason for hiding this comment

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

@Morriz this PR is a mess that you have made.
There are way too many changes that you did not agree with the team.
This is not healthy. You also removed a lot of tests without justifying it.
The Wild West coast of yours makes the team highly inefficient.

@Morriz
Copy link
Contributor

Morriz commented Apr 15, 2021

The changes are refactoring changes, not functional. None of those unit tests I removed tested any of the code we have. Please check your statements.

@Morriz
Copy link
Contributor

Morriz commented Apr 15, 2021

It is far from a "mess" imo and is a better starting point to create any tests on iyam. Fortunately, the tasks are extremely robust and idempotent, and well tested manually. So I am not afraid about missing tests here. I urge any in our team to really read up on testing practices and only write tests that cover our code paths. I can present one in this repo next week as an example...

@Morriz Morriz merged commit 0e58f0c into master May 6, 2021
@delete-merged-branch delete-merged-branch bot deleted the gitea-drone branch May 6, 2021 15:36
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.

Create OAuth app credentials
3 participants