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

mysql: user__token table has incorrect VARCHAR size for id field #303

Closed
neilmcgibbon opened this issue Mar 17, 2017 · 1 comment
Closed

Comments

@neilmcgibbon
Copy link

When calling the API to create a user token (POST /user/tokens) I was met with an HTTP 500.

The panic included (part of trace removed for brevity):

Error 1406: Data too long for column 'id' at row 1
/usr/local/Cellar/go/1.8/libexec/src/runtime/panic.go:489 (0x42875f)
...
/Users/m/p/go/src/github.com/ansible-semaphore/semaphore/api/user.go:50 (0x910ad4)
...

The code that creates the API token takes a 32 byte[] and base64 encodes it:

func createAPIToken(c *gin.Context) {
        //...
	tokenID := make([]byte, 32)
        // ...
	token := models.APIToken{
		ID:      strings.ToLower(base64.URLEncoding.EncodeToString(tokenID)),
                // ...
	}
        // ...
}

A 32 byte[] in base64 will yield a string of 44 characters: 4 * math.Ceil(32/3.0) = 44 (@see http://stackoverflow.com/questions/13378815/base64-length-calculation)

The user__token mysql table has an id field of 32 characters, this should be 44, so a migration of:

 ALTER TABLE `user__token` CHANGE COLUMN `id` `id` VARCHAR(44) NOT NULL;

This worked for me - not sure if its already been picked up, but I couldn't find it in issues.

@matejkramny
Copy link
Contributor

Thanks!

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

No branches or pull requests

2 participants